Skip to content

bug: stop the container when the CLI is terminated, not only on Ctrl+C - #712

Open
Amadeus-22 wants to merge 1 commit into
QuantConnect:masterfrom
Amadeus-22:fix/681-stop-container-on-sigterm
Open

Amadeus-22 wants to merge 1 commit into
QuantConnect:masterfrom
Amadeus-22:fix/681-stop-container-on-sigterm

Conversation

@Amadeus-22

Copy link
Copy Markdown
Contributor

Related to #681 (step 1 of the proposed solution)

Description

DockerManager.run_image registered its stop handler for SIGINT only. When a non-detached command such as a local lean live deploy received SIGTERM or SIGHUP (systemctl stop, timeout, a closed SSH session, a cancelled CI job or pod), the CLI exited with 143 and the LEAN container kept running, still trading.

SIGTERM and SIGHUP now go through the same handler as Ctrl+C, so the container is stopped and removed the same way. SIGHUP is skipped on Windows, where it does not exist.

Steps 2 and 3 of the issue (labelling containers and refusing a second deployment of the same project) change the deploy flow, so they are left out of this PR.

How Has This Been Tested?

  • New test test_run_image_stops_the_container_when_the_cli_is_terminated in tests/components/docker/test_docker_manager.py: checks the handler is registered for SIGINT, SIGTERM and (where available) SIGHUP, and that SIGTERM kills the container. It fails on master and passes with the fix.
  • Against real Docker 29 on Linux, run_image on a container running sleep 600, then kill -TERM on the CLI:
    • master: CLI exits 143, the container is still running.
    • this branch: CLI exits 1, the container is gone.
  • Full suite: 2801 passed, 83 skipped (Python 3.13).

🤖 Generated with Claude Code

run_image only handled SIGINT, so a SIGTERM or SIGHUP to a non-detached
command (systemctl stop, timeout, a closed SSH session, a cancelled CI
job) ended the CLI with 143 and left the LEAN container running. Route
both signals through the existing handler. SIGHUP is skipped on Windows,
where it does not exist.

Part of QuantConnect#681.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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