You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixing builds for native led to a tests failing as documented in #51. The possible reason is covered in a comment.
After discussion, the current cause of the bug appears to be how the process is being cloned in the ghc runtime. It is likely that ghc RTS threads implemented using pthreads, is using clone call with flags that do not copy over the file descriptors.
With this assumption the sequence of steps that leads to the error are these -
Parent process creates a pipe
File descriptors are updated in green thread 1 (GT 1)
Parent process "clones" a child process on GT 1
Child process is moved to GT 2 because of scheduling
GT2 does not have fd structures of pipe created in GT 1. This is related to how threads have been implemented in GHC RTS.
Child process tries to close fds that do not exist
This is an intermittent issue because sometimes step 4 does not happen. This error also does not occur on using the process package because the library clones parent and child process using a c ffi function, somehow GHC makes sure process created through ffi stays on the same GT. Another point that validates the above cause is that tests pass when configured to run with 1 thread only.
You can try using a bound thread so that the entire computation is done in the same OS thread. Wrap createProc' in forkOS, and pass the results via an MVar. That should take care of this issue.
Notice that parent and child process ids are the same even though the child process is printing it's id in the exec action after forkProcess. And the fds printed in child action does contain fd 58. Below is the log when the test passes successfully.
Activity
twitu commentedon Jul 28, 2022
This issue is depends on fixing #34 #51
Fixing builds for native led to a tests failing as documented in #51. The possible reason is covered in a comment.
Originally posted by @twitu in #51 (comment)
harendra-kumar commentedon Aug 8, 2022
You can try using a bound thread so that the entire computation is done in the same OS thread. Wrap
createProc'inforkOS, and pass the results via an MVar. That should take care of this issue.twitu commentedon Aug 13, 2022
Very weird. Unbound thread is not making a difference. The error is consistently reproducing now. Even with with 1 thread!!
I've added some additional logs that print out the fds but that doesn't help much.
Notice that parent and child process ids are the same even though the child process is printing it's id in the
execaction afterforkProcess. And the fds printed in child action does contain fd 58. Below is the log when the test passes successfully.Logging logic is pushed to latest commit (ec53056) in
use-native