Skip to content

Commit f95b0a8

Browse files
hua7450claude
andcommitted
Force-recreate Google credentials file after snapshot restore
Modal preserves env vars across snapshot restore but not /tmp. configure_google_credentials() short-circuits when GOOGLE_APPLICATION_CREDENTIALS is set, so the env var survived the snapshot while the file at that path may not, leaving Cloud SQL Connector reads pointing at a missing credentials file. Pop the env var before calling configure_google_credentials() in the post-restore reset hook so the credentials file is rewritten on every container start. Addresses P1 review feedback on PR #1528. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3b29778 commit f95b0a8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

policyengine_household_api/modal_release/worker_app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ def reset_post_snapshot_state(self) -> None:
8686
# captured in the snapshot hold sockets that closed at snapshot
8787
# time. Reset them so the first request opens fresh connections.
8888
#
89-
# Also re-runs `configure_google_credentials()` in case Modal did
90-
# not preserve `/tmp` across snapshots and the credentials file is
91-
# missing on the restored filesystem.
89+
# Also force-recreate the Google credentials file: Modal preserves
90+
# env vars across snapshot restore, but /tmp is not guaranteed to
91+
# be preserved. Without popping the env var first,
92+
# configure_google_credentials() would short-circuit on the
93+
# surviving GOOGLE_APPLICATION_CREDENTIALS and leave it pointing
94+
# at a missing file, breaking analytics DB reconnects.
9295
# See: https://modal.com/docs/guide/memory-snapshot
96+
os.environ.pop("GOOGLE_APPLICATION_CREDENTIALS", None)
9397
configure_google_credentials()
9498

9599
from policyengine_household_api.data import analytics_setup

0 commit comments

Comments
 (0)