Skip to content

Bug: PID file is written before signal handlers are registered, leaving a window where SIGTERM is unhandled #46

@ChaseFlorell

Description

@ChaseFlorell

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

  • register_signal_handlers is called before write_pid_file in do_start
  • A SIGTERM received immediately after --start begins still triggers graceful cleanup
  • The PID file and stop sentinel are cleaned up on any termination path

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:mediumMedium priority

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions