server hangs on termination when running in a pipe
I run Xonotic server on Linux like xonotic-linux-dedicated.sh 2>&1 | tee -a server.log
inside a separate tmux session. This is in order to have interactive access to the server via terminal and also log everything to a file.
The problem occurs when I terminate the tmux session (tmux kill-session -t xonotic-server
): tee
exits, but the xonotic-linux-dedicated
process remains running and has high CPU usage.
When tmux terminates a session, it sends SIGHUP to the spawned processes. I suspect that tee
terminates first, that breaks the pipe, and the server cannot handle a broken pipe for stdout/stderr and just hangs.
Steps to reproduce:
$ ./xonotic-linux-dedicated.sh 2>&1 | tee -a /tmp/xonotic-log &
$ kill -SIGHUP <PID of the tee process>
$ # now try to terminate the server
$ kill -SIGHUP <PID of the server>
$ # the server is still running and doesn't exit, as seen in `ps aux | grep xonotic`
$ # only `kill -9` can terminate the server now
If I send SIGHUP
to the server first, then everything terminates correctly. If I run the server without the pipe, it terminates correctly too.
This happens with autobuild version 20240210. Didn't happen with 20230329.