Title: fix(db): retry the migration connection on transient slot exhaustion by waleedlatif1 · Pull Request #5226 · simstudioai/sim · GitHub
Open Graph Title: fix(db): retry the migration connection on transient slot exhaustion by waleedlatif1 · Pull Request #5226 · simstudioai/sim
X Title: fix(db): retry the migration connection on transient slot exhaustion by waleedlatif1 · Pull Request #5226 · simstudioai/sim
Description: Summary Migrations fail their deploy whenever the production/staging database is momentarily at its connection cap. The migration opens its session on the first query (the advisory-lock acquire); if every non-superuser slot is taken, that connect throws 53300 — "remaining connection slots are reserved for roles with the SUPERUSER attribute" — and the whole migrate step errors out, even though the spike clears within seconds. This adds a bounded connection retry before the lock is acquired. Why this approach (investigated via PlanetScale) The "give the migration role reserved slots" route is not available from here: on the prod cluster, max_connections (200), superuser_reserved_connections (3), and reserved_connections (0) are all context = postmaster — they only change with a database restart and are managed by PlanetScale's cluster sizing, not ALTER SYSTEM. The only online levers (capping the app role's connection limit, or granting pg_use_reserved_connections while reserved_connections = 0) are either ineffective or risk shifting the outage onto the app. The saturation is transient (the DB sits around ~30 connections and briefly spikes), and the migration is a single short-lived session — so retrying the connect is the correct, low-risk fix. Change connectWithRetry() runs SELECT 1 before acquireMigrationLock(), retrying 53300, the 08xxx connection_exception class, and the postgres-js transport codes with jittered backoff (10 attempts, ~90s ceiling). Non-transient errors (auth, bad host/db) still fail fast. Reuses the existing backoffWithJitter / getPostgresErrorCode helpers. Durable capacity follow-up (platform, not in this PR) The root cause is the app saturating ~all 200 slots at peak. Options for the owner to weigh: scale the cluster (raises max_connections), contain the app's pool / route through the pooler, or have PlanetScale set reserved_connections + grant the migration role pg_use_reserved_connections (and revoke it from the app role, which currently holds it). All require platform/cluster action. Type of Change Bug fix (deploy reliability) Testing biome + typecheck clean. Logic exercises on the next migration-bearing deploy; non-transient failures still surface immediately. Checklist Self-reviewed No secrets added or exposed I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: Summary Migrations fail their deploy whenever the production/staging database is momentarily at its connection cap. The migration opens its session on the first query (the advisory-lock acquire); i...
X Description: Summary Migrations fail their deploy whenever the production/staging database is momentarily at its connection cap. The migration opens its session on the first query (the advisory-lock acquire); i...
Opengraph URL: https://github.com/simstudioai/sim/pull/5226
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:9811e17d-6dbd-cca9-1138-13249c898e09 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CD48:39AF8:B5654:10082F:6AFB4621 |
| html-safe-nonce | 78f039894cfcb9cfc03abd1a08f5f4afaff4005732bd61f32d2b7e72c65a672c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDQ4OjM5QUY4OkI1NjU0OjEwMDgyRjo2QUZCNDYyMSIsInZpc2l0b3JfaWQiOiI3NDI3MTI2Mjg4MTk0NzgwNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | babc20a0c5935238cd68a844b427afb6a6657f03925c995c6a11eedc1f1d09a5 |
| hovercard-subject-tag | pull_request:3944347354 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/5226/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary Migrations fail their deploy whenever the production/staging database is momentarily at its connection cap. The migration opens its session on the first query (the advisory-lock acquire); i... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | acf7616d06cc051644705b379878c9bb13dc5e70ecf4ffd9b34140f8ac01d7e1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26504db649b58525278f77a52b80ba5f10d5f4de |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width