Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing a named pipe results in an error message #80

Open
renetenthije opened this issue Sep 27, 2023 · 1 comment
Open

Closing a named pipe results in an error message #80

renetenthije opened this issue Sep 27, 2023 · 1 comment

Comments

@renetenthije
Copy link

To reproduce, add the following lines to the Program class in DemoHost (just a place to quickly add this in the current codebase)

var myLogger = new Logger(logLevel: LogLevel.Debug, logDirectory: "C:/", messageBufferSize: 0);
const string pipeName = "myPipe";
var host = new NpHost(pipeName, myLogger);
host.AddService<IIPCBridge>(bridge);
host.Open();
host.Close();

The logfile will show the following error lines:

2023-09-27T15:22:10.003	Error	Error in ProcessRequest: System.IO.EndOfStreamException: Unable to read beyond the end of the stream.::   at System.IO.BinaryReader.InternalRead(Int32 numBytes)::   at System.IO.BinaryReader.ReadInt32()::   at ServiceWire.Host.ProcessRequest(Stream readStream, Stream writeStream) in *\src\ServiceWire\Host.cs:line 277
2023-09-27T15:22:10.048	Error	ProcessClientThread error: System.IO.IOException: Pipe is broken.::   at System.IO.Pipes.PipeStream.CheckWriteOperations()::   at System.IO.Pipes.PipeStream.Flush()::   at System.IO.BufferedStream.Flush()::   at System.IO.BufferedStream.Dispose(Boolean disposing)::   at System.IO.Stream.Close()::   at System.IO.BinaryReader.Dispose(Boolean disposing)::   at System.IO.BinaryReader.Close()::   at ServiceWire.Host.ProcessRequest(Stream readStream, Stream writeStream) in *\src\ServiceWire\Host.cs:line 317::   at ServiceWire.Host.ProcessRequest(Stream stream) in *\src\ServiceWire\Host.cs:line 252::   at ServiceWire.NamedPipes.NpHost.ClientConnectionMade(Object sender, PipeClientConnectionEventArgs args) in *\src\ServiceWire\NamedPipes\NpHost.cs:line 69::   at ServiceWire.NamedPipes.NpListener.ProcessClientThread(NamedPipeServerStream pipeStream) in *\src\ServiceWire\NamedPipes\NpListener.cs:line 85

When stopping the NpListener it makes a client.Connect call. See NpListener.cs, line 47

//make fake connection to terminate the waiting stream
try
{
         using (var client = new NamedPipeClientStream(PipeName))
         {
              client.Connect(50);
         }
}

Which in turn raises the ClientConnectionMade event in NpHost, which then tries to do

var stream = new BufferedStream(args.PipeStream);
base.ProcessRequest(stream);

On a pipe that is already closing (or closed already).
So far my quick investigation of the issue.
Not really critical, but closing should be smooth process without error messages in the log file I assume.

@tylerje
Copy link
Member

tylerje commented Jan 11, 2024

I'm hoping to free up some time soon to work on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants