python system_error ai_generated true

[Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use

ID: python/uvicorn-port-already-in-use

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-01-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.100+ active — — —
0.110+ active — — —

Root Cause

Previous uvicorn/gunicorn worker still holding the port, or another service bound to 8000 (common after Ctrl+C on reload).

generic

中文

先前的 uvicorn/gunicorn 工作进程仍占用端口,或另一服务绑定到 8000(reload 下 Ctrl+C 后常见)。

Workarounds

  1. 95% success
    lsof -i :8000  # then kill -9 <pid>
  2. 90% success
    uvicorn app:app --port 8001  # use a free port

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Reload spawns more workers; port stays held.

  2. 80% fail

    Same port conflict.