Repository navigation
fix: Stop Connect containers promptly by signaling Connect directly - #71
Merged
Merged
Conversation
Newer images run startup.sh as PID 1, which ignores SIGTERM, so stopping the container waited out Docker's 10 second grace period before killing it. with-connect sends SIGTERM to the Connect process instead, which shuts down cleanly in under a second, and falls back to a 2 second stop timeout. Fixes #56. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w it Adds tests that stop Connect through main() in --stop and command mode. Addresses roborev job 683. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 23, 2026
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #56.
Problem
The modern
ghcr.io/posit-dev/connectimage runsstartup.shas PID 1, with no SIGTERM trap and noexec. A shell running as PID 1 ignores SIGTERM, socontainer.stop()waits out Docker's grace period (10 seconds by default) and then SIGKILLs the container. That happens on every--stopand at the end of every command-mode run. The legacyrstudio/rstudio-connectimages don't have this problem, becausetiniforwards the signal.Fix
stop_connect_container()runspkill -TERM -f '^/opt/rstudio-connect/bin/connect( |$)'inside the container and waits up to 10 seconds for the container to exit. Ifpkilldoesn't match, isn't installed, or Connect doesn't exit in time, it falls back tocontainer.stop(timeout=2). This is the stop part of #53, adapted to how with-connect runs Connect without a keep-alive process.Both stop paths use it:
--stopand the cleanup inmain(). I also removed an extracontainer.stop()inwait_for_http_server(), because thefinallyinmain()already stops the container on that path.Verification
The pattern matches only the Connect server process, not
rserver-monitoror other children. It also matches under Rosetta on Apple Silicon.Using throwaway containers on the modern image:
container.stop()stop_connect_container()On my machine Docker gave containers a 1-second stop timeout, so the plain stop took about 1.2 s instead of the ~11 s in the issue. The fast stop also means Connect shuts down cleanly instead of being SIGKILLed.
On the legacy jammy image, signaling Connect directly exits cleanly in 0.27 s.
Unit tests cover the helper (signaling Connect,
pkillnot matching or not installed, exec errors, wait timeouts) and both stop paths throughmain().Merging with #70
This branch merges cleanly with #69. It has one small conflict with #70 in the
finallycleanup: keep #70'stry/exceptwarning and callstop_connect_container(container)inside it.🤖 Generated with Claude Code