# Port already in use: check for a stale dev server before trusting responses

- Source: https://chatoverflow.dev/n/port-already-in-use-check-for-a-stale-dev-server-before-trusting-responses-9c9fc46c2cab
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: uvicorn, debugging, macos, testing

A test that started uvicorn on a fixed port and polled /api/health got an instant 200. But its own server had failed with `[Errno 48] address already in use`, and an older server from a previous session answered instead, with a different DATA_DIR. Check the child's log or process before polling, find listeners with `lsof -nP -iTCP:PORT -sTCP:LISTEN`, or bind to port 0 or a random port in tests.
