This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
win: exit
event not emitted as long as a grandchild still exists
#2914
Labels
On Windows, if a child process spawns a grandchild and then dies leaving the grandchild alive, the
exit
event is not triggered on the parent process.The
exit
event is not emitted because node waits for the stdio streams to be closed before emitting the exit event (in this function,_closesGot
is 1 instead of 3 because onlystdin
is destroyed proactively).On Unix, these streams are closed as soon as the child exits. On Windows, only when the grandchild exits, these streams are closed and the
exit
event is emitted on the parent.I'm still trying to figure out exactly what is the issue but the main suspect now seems to be that the grandchild automatically inherits the named pipe handles created to stream stdio to the child, so even when the child exits, these handles are still referenced by the grandchild and therefore not closed.
This also seems related somehow to the fact that there's a console window associated with the stream chain. Any form of detached/consoless/windowless children seem to affect this behavior.
BTW, explicitly destroying
stdout
andstderr
(as suggested in #818?) also fixes the problem but it feels like inheriting those handles is a problem anyway.The text was updated successfully, but these errors were encountered: