From f6ee99801d17288cf21ce42e15aa4d3d740e5f82 Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 23 Jul 2026 20:04:34 +0200 Subject: [PATCH] Fix migration 'Too many connections' error during deploy - 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 --- .gitea/workflows/deploy.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 1d59f415..cab7e5ff 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -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