Report #101479
[bug\_fix] runtime error: invalid memory address or nil pointer dereference
Guard the dereference with a nil check, or guarantee initialization by using a constructor function, dependency injection, or \`sync.Once\` so the pointer is non-nil before use. Run \`go test -race\` to catch data races that can leave pointers nil on some paths.
Journey Context:
A service lazily initializes a config struct in an HTTP handler. Under load, a second goroutine reads the same pointer before the first goroutine finishes assigning it, triggering a nil pointer panic that only appears in production. The stack trace points to a line doing \`cfg.Timeout\`, but the real bug is two layers up: the pointer is declared at package level and assigned conditionally inside \`initConfig\(\)\`, with no synchronization. Adding a nil check stops the panic but hides the race. The durable fix is a constructor that returns an initialized struct and a \`sync.Once\` guard for the global instance, plus \`-race\` tests that reproduce the interleaving.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:55:29.864441+00:00— report_created — created