Clean error when dev apps ports are in use#3658
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5cfb1e6557
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| if s.connect_ex(("localhost", port)) == 0: |
There was a problem hiding this comment.
Probe both address families when checking occupied ports
The new preflight port check uses an IPv4-only socket (AF_INET) with connect_ex(('localhost', port)), so it misses listeners bound only on IPv6 (for example ::1). In that case this code reports the port as available, but later startup can still fail with address-in-use when binding host='localhost', which reintroduces the same noisy failure path this change is trying to prevent. Please check both families (e.g., via getaddrinfo) or use a bind-based availability check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12877449fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for family in (socket.AF_INET, socket.AF_INET6): | ||
| with socket.socket(family, socket.SOCK_STREAM) as s: |
There was a problem hiding this comment.
Skip unsupported address families during port preflight
The new preflight check unconditionally creates an AF_INET6 socket, which raises OSError (EAFNOSUPPORT) on environments where IPv6 is disabled or unavailable (common in containers and hardened hosts). In that case fastmcp apps dev now fails before startup with a traceback even when the requested ports are free, which is a regression from the prior behavior. Please catch unsupported-family errors (or derive probe targets from getaddrinfo) so IPv4-only environments can still run.
Useful? React with 👍 / 👎.
Before: full traceback with OSError, SystemExit, uvicorn internals, and asyncio cleanup noise.
After:
Checks both ports before starting anything.