Repository navigation
fix: retry managed marimo startup after losing its port - #122
Merged
Merged
Conversation
ManagedServer picks a free loopback port and closes the socket before marimo binds it, seconds later after imports. Another process can take the port in between, uvicorn exits with an address-in-use error, and the build fails with an opaque server_start_failed. When an exited server's log reports an address in use, stop its process tree, truncate the log, and start again on a fresh port, bounded by five attempts and one startup deadline. Every other early exit still fails at once. Startup failures now append the exit code and the last server log lines to the message, so CLI and test output name the cause.
Readiness polling sends the bearer token to whichever process holds the port, so a server that lost its port race also lost its token. Each attempt now starts with a fresh token. The retry cleanup runs inside the failed attempt's handler, so a cleanup failure keeps the port error as its context. Startup diagnostics drop a line cut by the 8 KiB window, which could otherwise leave an unredacted token fragment, and details.log keeps the end of the rendered log, where the failure is reported.
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.
ManagedServerpicks a free loopback port, closes the probe socket, and hands the port to marimo, which binds it only after its imports finish. Another process can take the port in that window. uvicorn then exits with an address-in-use error and the build fails with a barethe managed marimo server exited during startup. Parallel test workers hit this in CI, and so can several builds or captures running at once on one machine.When an exited server's log reports an address in use (errno 98, 48, or 10048, or
address already in use), the owner now stops that process tree through its usual cleanup, truncates the log, and starts again with a fresh port and a fresh access token. Readiness polling may already have sent the old token to whoever held the port. Five attempts and the existing startup deadline bound the retries. Every other early exit still fails at once.Startup failures that read the server log now end their message with the exit code and the last three log lines, redacted, for example
exited during startup with code 1: ... | AttributeError: module 'uvicorn' has no attribute '__version__'. The redacted log indetails.lognow keeps its end, where the failure is reported.