Skip to content

fix: shut down gracefully on SIGTERM - #481

Merged
nanomad merged 2 commits into
developfrom
fix/graceful-sigterm-shutdown
Oct 17, 2026
Merged

nanomad merged 2 commits into
developfrom
fix/graceful-sigterm-shutdown

Conversation

@nanomad

@nanomad nanomad commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

In a container the gateway runs as PID 1. Python installs no SIGTERM handler, and the kernel ignores a default-action SIGTERM for PID 1, so docker stop waited 10 s and then sent SIGKILL. The finally that closes the SAIC API client (#479) and other cleanup never ran.

  • Add run_until_terminated() in src/shutdown.py. On SIGTERM it cancels the main task, so finally blocks run, and the process exits with code 0. Exceptions and other cancellations (such as Ctrl-C) are not swallowed. If a handler can't be installed on the platform, it is skipped.
  • Use it in src/main.py.
  • Add .git/, .claude/ and tests/ to .dockerignore to keep them out of the build context. README.md stays, because pyproject.toml declares it as the readme.

Tested: five unit tests (including a real SIGTERM), and a subprocess run where SIGTERM runs the cleanup and exits with code 0. Ruff, mypy and the full suite pass (323 tests). Not tested: a real docker stop against the built image.

@nanomad
nanomad merged commit 1010e95 into develop Oct 17, 2026
6 checks passed
@nanomad
nanomad deleted the fix/graceful-sigterm-shutdown branch October 17, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant