runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.IO.Pipes; NamePipeServerStream hangs when trying to connect when using SafePipeHandle parameter on constructor

Open bpschoch opened this issue 11 years ago • 2 comments

[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

bpschoch avatar May 15 '15 19:05 bpschoch

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.

stephentoub avatar Jun 01 '15 14:06 stephentoub

Fixed by dotnet/corefx#1884

stephentoub avatar Jun 03 '15 03:06 stephentoub