Repository navigation
Make Process.Start wait for child process to exec - #5421
Conversation
|
Test Innerloop Windows_NT Debug Build and Test please (GitHub cloning timeout) |
|
@stephentoub Thanks for looking at it. I love the solution :). One question though, we do a blocking read on essentially an empty pipe and so rely on it returning due to pipe closing, would we not want to check on the exact error as well? |
😄
And do what if it's not what we expect? At this point we've already forked the child, so we should really be returning a Process object that lets the caller understand the state of the child process, which means we shouldn't error out based on this operation. (That said, I should probably check for EINTR and repeat the read in that case; I'll do that.) |
We use fork/exec to spawn child processes in System.Diagnostics.Process. This also means we face a flaw in this design that there's a period of time where the child process isn't actually running the target program, which means that the Process we get back may report information related to the parent process' clone rather than to the desired child's information, e.g. the ProcessName may come back as "corerun" rather than the name of the program that will be exec'd. As a workaround, on systems that have pipe2 (i.e. Linux), this commit augments the fork/exec logic to create a pipe with the O_CLOEXEC flag. That way, the child process will close the pipe when exec transitions the process to the child program, breaking the pipe. The parent process then waits for the pipe to be broken and doesn't return from the start routine until the child has transitioned.
0c1959a to
a1f16ad
Compare
Make Process.Start wait for child process to exec
|
You people are fast, thanks for improving this! |
The updated packages fix our Start/Stop process tests, which were failing intermittently due to the process name appearing incorrect. See dotnet/corefx#5421 for further details.
…_to_start Make Process.Start wait for child process to exec Commit migrated from dotnet/corefx@5b3461d
We use fork/exec to spawn child processes in System.Diagnostics.Process. This also means we face a flaw in this design that there's a period of time where the child process isn't actually running the target program, which means that the Process we get back may report information related to the parent process' clone rather than to the desired child's information, e.g. the ProcessName may come back as "corerun" rather than the name of the program that will be exec'd.
As a workaround, on systems that have pipe2 (i.e. Linux), this commit augments the fork/exec logic to create a pipe with the O_CLOEXEC flag. That way, the child process will close the pipe when exec transitions the process to the child program, breaking the pipe. The parent process then waits for the pipe to be broken and doesn't return from the start routine until the child has transitioned.
cc: @pallavit
Fixes https://github.com/dotnet/corefx/issues/5378#issuecomment-171704893