Repository navigation
fix: Keep polling for Connect's port until the timeout - #75
Merged
Merged
Conversation
is_port_open() made a single TCP connect right after the container started. On Docker Desktop the published port can take a fraction of a second to bind, so the connect was refused instantly and with-connect reported "did not start within 60 seconds" in milliseconds. Retry the connection every 0.25 seconds until the deadline. While waiting, check the container status and stop early if it has exited, reporting that the container exited instead of a timeout. Fixes #57. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Avoids a merge conflict with #72, which adds tests after test_valid_license_http_server_starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #57.
Problem
is_port_open()made one TCP connect right after the container started. On Docker Desktop the published host port can take a fraction of a second to bind aftercontainers.run()returns. During that window the connect is refused at once, so with-connect reported "Posit Connect did not start within 60 seconds" after a few milliseconds, then stopped a container that was starting normally. Thetimeout=60.0only limited how long a single connect attempt could take. It didn't make with-connect keep trying.Fix
is_port_open()retries every 0.25 seconds (poll_interval) until the timeout expires. Each attempt's connect timeout is capped at the time left. After a failed attempt it sleeps for whichever is shorter, the poll interval or the time left, so it keeps trying right up to the deadline.is_port_open()takes an optionalcontainer. On each attempt it callscontainer.reload()and stops waiting if the status isexitedordead, so a Connect that crashes on startup doesn't wait the full 60 seconds. The call site passes the container and raises "Posit Connect container exited before port N opened." in that case. A timeout still raises the "did not start within 60 seconds" error.Verification
Run locally on macOS with Docker Desktop and
ghcr.io/posit-dev/connect:latest:uv run main.py --license README.md --image ghcr.io/posit-dev/connect:latest --port 43821 -- truegot past "Waiting for port 43821 to open...", logged "Running Posit Connect v2026.10.0", and failed as expected with "Unable to obtain a valid license" (README.md stands in for a license, since no valid one was available).containers.run()returned after the port was already bound. To exercise it, a script polled a port and started the container 2 seconds later withdocker run -p:ConnectionRefusedErrorafter 0.001s.is_port_open()returnedTrueafter 2.3s and 10 attempts.false,is_port_open(..., container=c)returnedFalseright away (statusexited) instead of waiting 60s.Tests
Added after
test_extract_server_version_devand registered in the__main__block:test_is_port_open_retries_until_port_opens: two refused connects, then a success, givesTrueafter 3 attempts.test_is_port_open_times_out_on_closed_port: a closed local port givesFalseafter the full 0.5s timeout, not right away.test_is_port_open_stops_when_container_exits: an exited container givesFalsewithout trying to connect.uv run test_main.pyanduv run --with pytest pytest -qpass.Merge conflicts with other open PRs
fix-command-errors), fix: Report Docker and installed-command errors as a short message #70 (clean-errors), fix: Stop Connect containers promptly by signaling Connect directly #71 (fast-stop), feat: Use a free port when 3939 is in use and --port isn't given #73 (auto-port): merge cleanly (checked withgit merge-tree).stream-startup-logs): one small conflict inmain.pyat theis_port_opencall site, because both PRs change the same lines. To resolve it, keepcontainer=containerand the exited-status check from this PR, and replace the twoContainer logs:print lines with feat: Stream Connect's startup logs to stderr while waiting for it to start #72'sstartup_logs.dump().test_main.pymerges cleanly.🤖 Generated with Claude Code