The server stops working
See original GitHub issueDescribe the bug
I am looking for a reliable named pipes server for communication between C ++ and C #. Unfortunately, the H.Pipes server can easily crash due to an error in the client. Here’s an example code that shows how to make the server stop responding to new connections:
Steps to reproduce the bug
- Run ConsoleApp from samples as server
- Connect to server by the following code:
using System;
using System.IO.Pipes;
using System.Net;
using System.Threading;
namespace HPipeError
{
internal class Program
{
private static void Main(string[] args)
{
var pipeClient = new NamedPipeClientStream("named_pipe_test_server");
while (!pipeClient.IsConnected)
{
pipeClient.Connect();
Thread.Sleep(100);
}
// read string length
var buffer = new byte[sizeof(int)];
pipeClient.Read(buffer, 0, sizeof(int));
var len = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buffer, 0));
// read string content
buffer = new byte[len];
pipeClient.Read(buffer, 0, len);
}
}
}
- After executing this code, try to connect to the server (e.g. using SampleApp as a client). It will be impossible.
Expected behavior
No response
Screenshots
No response
NuGet package version
No response
Platform
No response
IDE
No response
Additional context
Why is this happening?
After establishing the connection by the client, the server sends the name of the pipe created for the client through the main pipe. The server then waits for the client to establish a connection to the newly created pipe, but unfortunately the main pipe is closed. If the client fails to connect, the main pipe will not be recreated and you will not be able to connect to the server anymore. So one malfunctioning client can therefore block the server.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
For now I added a test for this case and confirmed the issue.
Thanks for bringing this up. I will take a look now