Hello!
I believe I found a bug in waitForProcess. When run in the MaskedInterruptible state, an async exception doesn't actually bring the thread down.
For example, the typed-process library exports withProcess which is similar to withCreateProcess, but ends up calling waitForProcess in the cleanup action of a bracket.
Even though waitForProcess is an interruptible foreign call, I think what's happening is:
- Async exception enqueued for delivery to thread making
waitForProcesscall - GHC sees it's in an
interruptibleforeign call, sendsSIGPIPE(GHC docs) c_waitForProcessreturns-1with errno =EINTR- Upon returning to Haskell, the pending exception is not delivered, because the masking state is
MaskedInterruptible c_waitForProcessis retried because it's wrapped bythrowErrnoIfMinus1Retry_
So our "interruptible" waitForProcess is only half-interrupted :)
My fix in this patch is to simply poll for any async exceptions before entering c_waitForProcess. Here is some related discussion I had with @snoyberg.
Thanks!