akseljoonas HF Staff Claude Opus 4.6 commited on
Commit
c99fbe6
·
1 Parent(s): 9aea4e6

fix: prevent port conflict in HF Spaces dev mode

Browse files

Dev mode spawns CMD multiple times on restart, causing EADDRINUSE.
Wrap uvicorn in a start script that kills any prior instance first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. Dockerfile +1 -1
  2. backend/start.sh +7 -0
Dockerfile CHANGED
@@ -56,4 +56,4 @@ EXPOSE 7860
56
 
57
  # Run the application from backend directory
58
  WORKDIR /app/backend
59
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
56
 
57
  # Run the application from backend directory
58
  WORKDIR /app/backend
59
+ CMD ["bash", "start.sh"]
backend/start.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Entrypoint for HF Spaces dev mode compatibility.
3
+ # Dev mode may spawn the CMD multiple times; kill any prior
4
+ # uvicorn instance so the new one can bind the port.
5
+ pkill -f "uvicorn main:app" 2>/dev/null || true
6
+ sleep 0.3
7
+ exec uvicorn main:app --host 0.0.0.0 --port 7860