Repository navigation
fix(dash): refuse a busy or out-of-range --port before printing the URL - #736
Open
dchaudhari7177 wants to merge 2 commits into
Open
dchaudhari7177 wants to merge 2 commits into
dchaudhari7177 wants to merge 2 commits into
Conversation
dash printed the dashboard link before uvicorn tried to bind, and --port had no range check, so a busy port gave a dead link and a raw bind error, and --port 70000 a traceback. Bound --port to 1..65535 (exit 2), and probe the port with a throwaway bind before printing the URL or starting the heartbeat, exiting 1 with one error line when it is taken. Closes DobermanCore#714
This branch has not been deployed
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.
Closes #714 (and its PostHog twin #727).
What changes
doberman dashused to printDashboard: http://127.0.0.1:<port>/?token=…before uvicorn tried to bind. A busy port gave a dead link followed by uvicorn's[Errno 10048], and--port 70000a traceback ending inOverflowError.--porthasmin=1, max=65535, so an out-of-range port is a Typer usage error (exit 2). That also covers0and negatives._dash_port_is_free(port)does a throwaway bind on(_DASH_HOST, port)and closes it. If the bind fails,dashprintserror: port N is already in use, try --port <another>to stderr and exits 1. It doesn't print the URL or calluvicorn.run.SO_REUSEADDR, as uvicorn does, so a port only lingering inTIME_WAITis not reported busy. On Windows the option is left off, because there it would let the probe bind a port that is actually in use.docs/CLI.md's per-command exit-code table gets adash2row (port out of range), and the existingdash1row now also covers a busy port.Tests (
tests/unit/test_dash_serve.py)test_dash_refuses_a_busy_port_before_printing_the_urlholds a listening socket on a port and runsdash --port <that port>. It asserts exit 1, the error line, noDashboard:line,uvicorn.runnever called (monkeypatched), and the heartbeat never touched.test_dash_out_of_range_port_is_a_usage_error, parametrized over0,70000and-1: exit 2, no URL, nouvicorn.run.test_dash_disables_uvicorn_access_logused--port 0, which the new range check refuses. It now picks a free port.On
mainthese give 4 failed, 19 passed. On this branch the file passes 23/23, andpytest tests/unit -k "cli_help or docs or dash or exit_code"gives 342 passed, 1 skipped. ruff check and format are clean. Run on Windows / Python 3.12.One thing I noticed but didn't change: the "Collision audit" paragraph in
docs/CLI.mdsaysgrep -c "typer.Exit(code=" src/doberman/cli/main.pyreturns 67, butmainalready returns 88 (66 ×code=1, 20 ×code=2). This PR adds one morecode=1. Happy to refresh that paragraph here or in a separate docs PR.AI assistance: I used an AI assistant while writing this change and the tests. I reviewed the diff and ran the tests above myself.