From ac4a3aef1d92ca70bf668a65b1c7356abcd36822 Mon Sep 17 00:00:00 2001 From: Chris Hondl Date: Fri, 17 Jul 2026 09:29:52 -0700 Subject: [PATCH] fix: pool_pre_ping + recycle so idle DB connections don't crash the ETL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- backend/src/db/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/db/main.py b/backend/src/db/main.py index 4f0719af..dcbf0c32 100644 --- a/backend/src/db/main.py +++ b/backend/src/db/main.py @@ -3,7 +3,12 @@ from src.constants import CONN_STR -engine = create_engine(CONN_STR) +# pool_pre_ping: a pooled connection idle across the hourly-cron gap goes stale +# (Cloud SQL / db-f1-micro / the Cloud SQL proxy reap idle connections), and the +# next query raises "server closed the connection unexpectedly", 500ing the ETL +# trigger and stalling ingestion. pre_ping reconnects transparently; recycle +# drops connections older than 30 min proactively. +engine = create_engine(CONN_STR, pool_pre_ping=True, pool_recycle=1800) Session = sessionmaker(bind=engine)