From 0a410243dea33f204764000be81814e541dcae48 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Tue, 4 Aug 2026 20:10:25 +0000 Subject: Fix production wedge: propagate context to Google Calendar API calls Three .Do() calls in google_calendar.go accepted a ctx parameter but never chained .Context(ctx) into the actual SDK call, so the existing global 60s request timeout never reached the blocking network call. One hung Google Calendar request wedged every DB/session-touching request path in production for three days (2026-08-01 through 2026-08-04), undetected because /health unconditionally returned 200 throughout. - Wire .Context(ctx) into GetUpcomingEvents, GetEventsByDateRange, and GetCalendarList. - Bound aggregateData's four external fetches with a per-fetch sub-context as defense-in-depth (only effective if the callee actually honors ctx -- documented as such, not oversold). - Make GetUpcomingEvents/GetEventsByDateRange fetch calendars concurrently instead of sequentially: a review of this fix caught that a shared per-fetch deadline over a sequential loop would starve calendars past the first under any real latency, silently caching partial results as complete. Concurrent fetches give every calendar an equal shot at the same deadline instead. - /health now does a real PingContext DB check instead of a static "ok" (Handler.PingDB, tested for both healthy and closed-DB cases). - Add internal/api/context_audit_test.go: an AST-based structural guard that fails any future .Do() call in google_*.go missing .Context(...) anywhere in its chain, so this class of bug can't silently recur. Verified by deliberately reintroducing the original bug against a backup and confirming the guard catches it. - Add scripts/health-watchdog.sh: cron job restarts the service if /health fails twice in a row, five minutes apart. go test ./... -race is green. Deployed and live-verified. --- internal/config/constants.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'internal/config/constants.go') diff --git a/internal/config/constants.go b/internal/config/constants.go index 9eba843..1311302 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -21,6 +21,12 @@ const ( // RequestTimeout is the timeout for individual HTTP requests RequestTimeout = 60 * time.Second + + // HealthCheckTimeout bounds the DB ping /health performs. Short and + // separate from HTTPClientTimeout: a health check that itself hangs for + // 15s isn't fast enough for a watchdog polling every few minutes to be + // useful. + HealthCheckTimeout = 3 * time.Second ) // Default meal times (24-hour format) -- cgit v1.2.3