Skip to content

Clean error when dev apps ports are in use#3658

Merged
jlowin merged 3 commits intomainfrom
fix-dev-apps-port-error
Mar 27, 2026
Merged

Clean error when dev apps ports are in use#3658
jlowin merged 3 commits intomainfrom
fix-dev-apps-port-error

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Mar 27, 2026

Before: full traceback with OSError, SystemExit, uvicorn internals, and asyncio cleanup noise.

After:

ERROR    Port 8080 (dev UI) is already in use. Try --mcp-port or --dev-port to use different ports.

Checks both ports before starting anything.

@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. labels Mar 27, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/fastmcp/cli/apps_dev.py Outdated
Comment on lines +1637 to +1638
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(("localhost", port)) == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/fastmcp/cli/apps_dev.py Outdated
Comment on lines +1638 to +1639
for family in (socket.AF_INET, socket.AF_INET6):
with socket.socket(family, socket.SOCK_STREAM) as s:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@jlowin jlowin merged commit 2a2f4c8 into main Mar 27, 2026
8 checks passed
@jlowin jlowin deleted the fix-dev-apps-port-error branch March 27, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. enhancement Improvement to existing functionality. For issues and smaller PR improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant