SIGTERM does not terminate swipl v8.4 on some systems
Summary
On some systems, SIGTERM (e.g. using kill) doesn't terminate the swipl process. SIGKILL (e.g. kill -9) does still kill the process.
Background
We first ran into this issue after trying to use v8.4.0 for TerminusDB. We didn't have the problem with v8.2.4 and earlier.
The problem has appeared on Debian Linux and macOS, but not on every system or installation of SWI-Prolog. In particular, it doesn't appear on the official Docker images for swipl:8.2.4 and swipl:8.4.1. Also, a previous SWI-Prolog v8.4.0 on macOS did not exhibit the problem, but one v8.4.1 installed from source does exhibit it.
The problem showed up in some TerminusDB unit tests, which spawn a swipl process using process_create(..., ..., [process(PID), ...]), kill the process using process_kill(PID), and wait for the process using process_wait(PID, _). The process_wait would hang indefinitely. If we change process_kill(PID) to process_kill(PID, 9), process_wait does not hang.
We also confirmed that, after simply running swipl (with no arguments) and looking up the process ID with either ps or the predicate process_id, we could not kill the swipl process from another shell.
Conclusion
This is the only remaining issue we've encountered that prevents us from upgrading to SWI-Prolog v8.4 for TerminusDB. We can work around it in our tests using process_kill(PID, 9). But it does make us wonder what's happening.
It may be difficult to debug this problem if you can't reproduce it yourself. If you can give us any suggestions on what to try or where to look, we'd be happy to help.
It may be difficult to debug this problem if you can't reproduce it yourself. If you can give us any suggestions on what to try or where to look, we'd be happy to help.
I've never seen this happen (recently). Are you using on_signal/3? It is indeed a bit hard for me to help as long as I cannot reproduce this. As you've got it setup, I guess the simplest way is to get the hanging situation and use
gdb swipl PID
to attach gdb to the hung process to get a stack trace. Note that you can get a Prolog backtrace by switching gdb to the suspect thread and use printf "%s\n", PL_backtrace_string(25,0). Alternatively, compile SWI-Prolog for debugging and use -d channel
options to activate some of the debug channels. Most of the tricky stuff to handle termination is in pl-thread.c.