runtime
runtime copied to clipboard
System.IO.Pipes; NamePipeServerStream hangs when trying to connect when using SafePipeHandle parameter on constructor
[Fact]
public static void ServerCloneTests()
{
const string pipeName = "fooclone";
byte[] msg1 = new byte[] { 5, 7, 9, 10 };
byte[] received1 = new byte[] { 0, 0, 0, 0 };
using (NamedPipeServerStream serverBase = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte))
{
using (NamedPipeServerStream server = new NamedPipeServerStream(PipeDirection.InOut, false, false, serverBase.SafePipeHandle))
{
using (NamedPipeClientStream client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None))
{
Task clientTask = Task.Run(() =>
{
client.Connect();
client.Write(msg1, 0, msg1.Length);
int serverCount = client.NumberOfServerInstances;
Assert.Equal(1, serverCount);
});
}
server.WaitForConnection();
int len1 = server.Read(received1, 0, msg1.Length);
Assert.Equal(msg1.Length, len1);
Assert.Equal(msg1, received1);
}
}
}
This test hangs
The test is buggy: it's closing the client stream as soon as it's scheduled the task to connect from the client. Since it's then ignoring the clientTask and never awaiting it, the exceptions that are getting generated are getting ignored, too. I have a fix locally and will submit it as part of a set of pipes-related fixes.
Fixed by dotnet/corefx#1884