Fix migration 'Too many connections' error during deploy
Deploy / release (push) Skipped
Deploy / deploy (push) Failing after 2m56s

- pm2 stop now uses --kill-timeout 10000 for graceful shutdown
- Wait 10s after stopping (was 3s) for MariaDB to reclaim connections
- Migration retries increased from 5 to 10 with 5s wait (was 3s)
- Total retry window: ~50s instead of ~15s
This commit is contained in:
openhands committed 2026-07-23 20:04:34 +02:00
1 parent 7fc7412f18
commit f6ee99801d
1 file changed
+6 -6
+6 -6
View File
@@ -338,21 +338,21 @@ jobs:
echo "Cutover: stop service (free DB connections), migrate, swap .next..."
CUTOVER_STARTED=1
pm2 stop next || true
# Give MariaDB a moment to reclaim the live pool.
sleep 3
pm2 stop next --kill-timeout 10000 || true
# Wait for PM2 to fully exit and MariaDB to reclaim connections.
sleep 10
# Migrate only after live is stopped — avoids ER_CON_COUNT_ERROR while
# the old process still holds DATABASE_POOL_SIZE connections.
cd "${STAGE}"
MIGRATE_OK=0
for i in 1 2 3 4 5; do
for i in $(seq 1 10); do
if pnpm db:migrate; then
MIGRATE_OK=1
break
fi
echo "migrate attempt ${i}/5 failed (likely DB connections), retrying..."
sleep 3
echo "migrate attempt ${i}/10 failed (likely DB connections), retrying..."
sleep 5
done
if [ "${MIGRATE_OK}" != "1" ]; then
echo "ERROR: db:migrate failed after retries" >&2