Problem
In do_start, _prepare_stream_process (which calls write_pid_file) is called before register_signal_handlers(). If a SIGTERM or SIGINT arrives in the window between those two lines, the signal is handled by the default OS handler: the process dies immediately without:
- Writing the stop sentinel (
stream.stop)
- Cleaning up the PID file
- Transitioning the broadcast to
complete
The result is an orphaned broadcast in a non-complete state and a stale PID file that will cause the next --start to attempt to kill a process that no longer exists.
Proposed Fix
Register signal handlers before writing the PID file:
register_signal_handlers(config, logger)
write_pid_file()
Acceptance Criteria
Proposed Tests
test_signal_handlers_registered_before_pid_write — use unittest.mock to assert register_signal_handlers is called before write_pid_file within do_start
test_sigterm_during_startup_cleans_up — mock signal delivery immediately after handler registration; assert PID file is removed and stop sentinel is not left behind
Problem
In
do_start,_prepare_stream_process(which callswrite_pid_file) is called beforeregister_signal_handlers(). If a SIGTERM or SIGINT arrives in the window between those two lines, the signal is handled by the default OS handler: the process dies immediately without:stream.stop)completeThe result is an orphaned broadcast in a non-complete state and a stale PID file that will cause the next
--startto attempt to kill a process that no longer exists.Proposed Fix
Register signal handlers before writing the PID file:
Acceptance Criteria
register_signal_handlersis called beforewrite_pid_fileindo_start--startbegins still triggers graceful cleanupProposed Tests
test_signal_handlers_registered_before_pid_write— useunittest.mockto assertregister_signal_handlersis called beforewrite_pid_filewithindo_starttest_sigterm_during_startup_cleans_up— mock signal delivery immediately after handler registration; assert PID file is removed and stop sentinel is not left behind