-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
waitForProcess race condition #46
Comments
I worked around this limitation in streaming-commons. I'm not sure if On Wed, Oct 28, 2015, 12:41 PM Joey Hess notifications@github.com wrote:
|
I ran into the same issue today, on a Linux machine (RTS -N, kernel 4.4.0). I also ended up working around it by I wrote up a fix along the lines of @joeyh's suggestion at charles-cooper@fa0d45b; I won't have time to test it for a couple days but @snoyberg perhaps you could take a look and see if I'm heading in the right direction? |
It seems reasonable. My concerns would be (1) a negative performance hit and (2) breaking backwards compatibility. However, I lean towards doing this, as the bug here is significant enough. I'll look into this some time next week. |
Upon further inspection it seems the bug is due not to a race condition but failure to interpret the return code of
Handling the case accordingly (charles-cooper@e70eb47) seems to fix the bug. |
Previously an exception was being thrown when multiple threads were blocking on waitForProcess due to inconsistent handling of the return code of `waitpid`: "If more than one thread is suspended in waitpid() awaiting termination of the same process, exactly one thread returns the process status at the time of the target child process termination. The other threads return -1, with errno set to ECHILD." `getProcessExitCode` was handling the ECHILD case by returning 1, but `waitForProcess` was returning (-1) in all cases. For consistency this commit follows the approach in getProcessExitCode, returning 1 to the caller of c_waitForProcess if errno is ECHILD, thus avoiding throwing an exception in the calling code. Fixes haskell#46
I've been observing a similar bug on Windows for a while, and only today did I manage to track it down. If I call
Then I get an error about 5% of the time. A most annoying bug, and one I would encourage something be done to fix. |
This is a small race condition indeed, but today I managed to stumble over it, on a Linux system. I have a situation where 2 threads both need to wait for the same process to exit, so both call waitForProcess. One of the threads would then fairly reliably crash with "waitForProcess: does not exist (No child processes)"
Of course, I can work around it in my code by adding my own locking so only 1 thread calls waitForProcess on a process at a time. It could be similarly fixed in System.Process.. add another MVar to ProcessHandle, and make waitForProcess use it to prevent concurrent calls to c_waitForProcess
The text was updated successfully, but these errors were encountered: