runtime: ObjectDisposedException on Process.Start leaves defunct process on Linux

This is a difficult one to reproduce!

We’re starting a process repeatedly in 5 seconds gaps. After leaving running for a week, we end up with 4-5 defunct processes that failed to start. On the ones that failed we see the process handle is marked as invalid and an exception (see below) is thrown. Even though we’re disposing, the process now has a defunct child for it’s lifetime.

C# details:

  • Self contained deployment
  • DotNetCore 2.0
  • Centos 7.3

Code to reproduce:

using (var process = new Process())
{
    process.StartInfo.FileName = "filename";
    process.StartInfo.Arguments = "arguments";
    process.StartInfo.RedirectStandardOutput = true;
    process.EnableRaisingEvents = true;
    process.Start();

    var output = process.StandardOutput.ReadToEnd();

    process.WaitForExit(MaxWaitTime);
}

Exception stack:

System.ObjectDisposedException: Safe handle has been closed
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at System.Threading.RegisteredWaitHandleSafe.SetWaitObject(WaitHandle waitObject)
at System.Threading.ThreadPool.RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, Object state, UInt32 millisecondsTimeOutInterval, Boolean executeOnlyOnce, StackCrawlMark& stackMark, Boolean compressStack)
at System.Threading.ThreadPool.RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, Object state, Int32 millisecondsTimeOutInterval, Boolean executeOnlyOnce)
at System.Diagnostics.Process.EnsureWatchingForExit()
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 24 (16 by maintainers)

Most upvoted comments

On the latest dotnet(2.1.4), I can still reproduce this bug with the above code. This bug seems to be not completely fixed . Can you check it?