Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
e10bf6b
1
Parent(s): 65b6449
fix: exit gracefully on port conflict in dev mode
Browse filesDev 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>
- 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
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|