Skip to content

FU-P13-T8: Prevent Web UI port collision from destabilizing MCP sessions#62

Merged
SoundBlaster merged 6 commits intomainfrom
feature/FU-P13-T8-web-ui-port-collision
Feb 16, 2026
Merged

FU-P13-T8: Prevent Web UI port collision from destabilizing MCP sessions#62
SoundBlaster merged 6 commits intomainfrom
feature/FU-P13-T8-web-ui-port-collision

Conversation

@SoundBlaster
Copy link
Owner

Description

Fixes an unhandled SystemExit exception from uvicorn's daemon thread when the Web UI port becomes occupied after is_port_available() returns True (TOCTOU race). Previously, run_server() caught OSError but not SystemExit(1), which uvicorn raises internally when port binding fails — this leaked as a PytestUnhandledThreadExceptionWarning in tests and as stderr noise in production.

Changes:

  • src/mcpbridge_wrapper/webui/server.py: extended run_server() to also catch SystemExit, printing a clear warning to stderr and returning cleanly so the daemon thread exits without an unhandled exception
  • tests/unit/test_main_webui.py: added test_toctou_systemexit_from_uvicorn_does_not_crash_thread to TestPortCollisionHandling — simulates uvicorn raising SystemExit(1) and asserts no exception propagates

Type of Change

  • Bug fix

Quality Gates

  • make test - All tests pass with ≥90% coverage
  • make lint - No linting errors
  • make format - Code is properly formatted
  • make typecheck - Type checking passes
  • make doccheck - Documentation is synced with DocC (if docs changed)

Results:

pytest: 472 passed, 5 skipped — PytestUnhandledThreadExceptionWarning resolved
ruff check src/: All checks passed
coverage: 95.6% (≥90% required)

Documentation Sync

  • Documentation changes are synced with DocC catalog (or N/A) — no docs/ files changed

Testing

  • Added/updated tests for new functionality
  • All tests pass locally
  • Manually tested the changes

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • Comments added for complex code
  • Documentation updated (if needed)
  • No new warnings generated
  • PR title is descriptive

@SoundBlaster SoundBlaster merged commit 3c55311 into main Feb 16, 2026
9 checks passed
@SoundBlaster SoundBlaster deleted the feature/FU-P13-T8-web-ui-port-collision branch February 16, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant