Skip to content

Closing a named pipe results in an error message #80

@renetenthije

Description

@renetenthije

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions