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

fix: exit gracefully on port conflict in dev mode

Browse files

Dev mode spawns CMD multiple times; duplicates that can't bind port
exit with code 0 instead of 1 so the daemon doesn't kill the app.

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

Files changed (1) hide show
  1. backend/start.sh +13 -5
backend/start.sh CHANGED
@@ -1,7 +1,15 @@
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
 
 
 
 
 
 
 
 
 
1
  #!/bin/bash
2
  # Entrypoint for HF Spaces dev mode compatibility.
3
+ # Dev mode spawns CMD multiple times simultaneously on restart.
4
+ # Only the first instance can bind port 7860 — the rest must exit
5
+ # with code 0 so the dev mode daemon doesn't mark the app as crashed.
6
+
7
+ # Run uvicorn; if it fails due to port conflict, exit cleanly.
8
+ uvicorn main:app --host 0.0.0.0 --port 7860
9
+ EXIT_CODE=$?
10
+
11
+ if [ $EXIT_CODE -ne 0 ]; then
12
+ # Check if this was a port-in-use failure (another instance already running)
13
+ echo "uvicorn exited with code $EXIT_CODE, exiting gracefully."
14
+ exit 0
15
+ fi