In [ticket:9330] we were exploring solutions to signal a PT to do clean shutdown on Windows. In [ticket:10006] dcf suggested a workaround using JobObjects, which has the nice property that the children shutdown even when their parent crashes or is killed (SIGKILL or TerminateProcess).
This raises the valid point, why don't we try to achieve this for all platforms? Since all PTs must already communicate via stdout back to Tor (or any parent process, such as a PT chainer), one way of detecting parent death is to check that stdout is still open.
Trac: Description: In [#9330 (moved)] we were exploring solutions to signal a PT to do clean shutdown on Windows. In [#10006 (moved)] dcf suggested a workaround using JobObjects, which has the nice property that the children shutdown even when their parent crashes or is killed (SIGKILL or TerminateProcess).
This raises the valid point, why don't we try to achieve this for all platforms? Since all PTs must already communicate via stdout back to Tor (or any parent process, such as a PT chainer), one way of detecting parent death is to check that stdout is still open.
We'll need to research whether we must write to the stream to detect it's closed, or if we can get away with doing something like poll or select.
to
In [ticket:9330] we were exploring solutions to signal a PT to do clean shutdown on Windows. In [ticket:10006] dcf suggested a workaround using JobObjects, which has the nice property that the children shutdown even when their parent crashes or is killed (SIGKILL or TerminateProcess).
This raises the valid point, why don't we try to achieve this for all platforms? Since all PTs must already communicate via stdout back to Tor (or any parent process, such as a PT chainer), one way of detecting parent death is to check that stdout is still open.
I found that you can make this idea work without any changes to tor. All you have to do is introduce a process that interposes between tor and the pluggable transport, and write the pluggable transport so that it interprets a closed stdin as a command to terminate. tor calls TerminateProcess on the buffer process, which dies immediately. The death of the buffer process closes the stdin of the pluggable transport.
Hmm, I'm thinking of wontfixing this in favor of #15435 (moved) (add a pt env var that indicates that stdin will be kept open, which all new tors will set with appropriate modifications to actually keep stdin in the child open).
Rationale is that, terminateprocess-buffer checks stdin instead of stdout, and the newer ticket has a branch that does the right thing. Thoughts?