I have a master and a slave program who interact through a pair of anonymous pipes.

The interaction looks like this:

  • Master creates two AnonymousPipeServerStream's
  • Master starts client process, giving him their .GetClientHandleAsString()
  • Master .DisposeLocalCopyOfClientHandle's both pipes
  • Master writes stuff to one pipe and reads stuff from the other one
  • Occasionally master forcefully terminates the slave from another thread (Process.Kill()), AND ALSO closes both pipe objects.

In very rare circumstances, upon slave termination, reading from the pipe on master's side blocks indefinitely - or sometimes definitely (e.g. for several minutes). I am not able to reproduce it on my local machine, but it happens from time to time on a large cluster.

I captured a dump of this situation, and here's what I saw:

Stacktrace of blocked master (I am 100% sure that at this moment the client process is already terminated):

000000000c83e488 000000007700fdba [NDirectMethodFrameStandalone: 000000000c83e488] Microsoft.Win32.UnsafeNativeMethods.ReadFile(Microsoft.Win32.SafeHandles.SafePipeHandle, Byte*, Int32, Int32 ByRef, IntPtr)
000000000c83e430 000007feeab32820 DomainBoundILStubClass.IL_STUB_PInvoke(Microsoft.Win32.SafeHandles.SafePipeHandle, Byte*, Int32, Int32 ByRef, IntPtr)*** WARNING: Unable to verify checksum for System.Core.ni.dll

000000000c83e540 000007feeac14574 System.IO.Pipes.PipeStream.ReadFileNative(Microsoft.Win32.SafeHandles.SafePipeHandle, Byte[], Int32, Int32, System.Threading.NativeOverlapped*, Int32 ByRef)
000000000c83e5a0 000007feeac14a23 System.IO.Pipes.PipeStream.ReadCore(Byte[], Int32, Int32)
000000000c83e610 000007fef0169d8f System.IO.BinaryReader.FillBuffer(Int32)
000000000c83e650 000007fef0169c8a System.IO.BinaryReader.ReadInt32()

I also looked at the AnonymousPipeServerStream object that's blocking, and at its state an

Edit
Report