Skip to content

[fix] DB connection resilience: pool_pre_ping so idle connections don't stall the ETL - #14

Closed
chondl wants to merge 1 commit into
masterfrom
fix-db-pool-connection
Closed

[fix] DB connection resilience: pool_pre_ping so idle connections don't stall the ETL#14
chondl wants to merge 1 commit into
masterfrom
fix-db-pool-connection

Conversation

@chondl

@chondl chondl commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Problem

A pooled SQLAlchemy connection left idle across the hourly-cron gap goes stale (Cloud SQL / db-f1-micro / the Cloud SQL proxy reap idle connections). The next query raises psycopg2.OperationalError: server closed the connection unexpectedly, which 500s /v3/site/update_curr_year (the scheduler was returning error code 13) and silently stalls all ingestion.

On the mirror this is why an offseason event's match schedule (2026 IRI: 75 matches, 15 played) stopped appearing — the ETL cycle kept crashing on the stale connection before it could ingest.

Fix

create_engine(CONN_STR, pool_pre_ping=True, pool_recycle=1800). pre_ping issues a lightweight liveness check and transparently reconnects a dead pooled connection; recycle proactively drops connections older than 30 min. Not offseason-specific — a general infra fix for any Postgres/CockroachDB deploy.

Verification

Deployed to the staging mirror (backend rev 00014). /v3/site/update_curr_year returns 200 repeatedly where it had been 500ing; 2026iri ingested its full 75-match schedule with predictions + results.

Notes

  • Already live on the staging branch (deployed) as a direct commit; this PR captures the same fix against master for review + easy promotion to main.
  • No behavior change beyond connection resilience.

A pooled connection left idle across the hourly-cron gap goes stale (Cloud SQL /
db-f1-micro / the Cloud SQL proxy reap idle connections). The next query then
raises 'server closed the connection unexpectedly', which 500s the ETL trigger
(/v3/site/update_curr_year) and silently stalls ingestion — on the mirror this
stopped offseason match schedules from appearing. pool_pre_ping reconnects
transparently; pool_recycle=1800 drops old connections proactively.

Deployed and verified on the staging mirror (backend rev 00014): the update
endpoint returns 200 repeatedly where it had been 500ing, and 2026iri ingested
its full match schedule.
@chondl
chondl deleted the branch master July 19, 2026 19:01
@chondl chondl closed this Jul 19, 2026
@chondl
chondl deleted the fix-db-pool-connection branch July 19, 2026 19:01
@chondl

chondl commented Jul 19, 2026

Copy link
Copy Markdown
Owner Author

Consolidated: this pool_pre_ping fix was folded into #25 [06] (cph-postgres-compat) so there's no introduce-bug-then-fix step. Branch deleted; commit preserved in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant