fix: guard eBPF map iteration until tracer.Run loads the collection#294
Merged
Conversation
handleEvents starts before tracer.Run so it can drain the events channel while init() replays existing pids. But its 5s ebpfStatsTicker can fire before the eBPF collection is loaded on slow nodes (cold verifier, burstable instances), and updateEbpfStatsAndActiveConns then panics: panic: runtime error: invalid memory address or nil pointer dereference ebpftracer.(*Tracer).ActiveConnectionsIterator(...) containers.(*Registry).updateEbpfStatsAndActiveConns Seen in prod as a burst of restarts (exit code 2) on a spot t3.2xlarge until the node warmed up. Present since the ticker was introduced (#219). Add an atomic ready flag set once the collection is loaded, and skip the stats pass until it is.
There was a problem hiding this comment.
Code Review
This pull request introduces a readiness check using an atomic boolean in the eBPF tracer to prevent accessing and iterating eBPF maps before they are fully loaded, which avoids a nil dereference panic in the container registry. The reviewer suggests a safer approach where the tracer is marked as ready only after its initialization successfully completes, preventing potential race conditions and incorrect state on initialization failure.
blue4209211
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Registry.handleEventsis started beforetracer.Run()(it must be —init()replays an event per existing pid into the channel, which can exceed the 2000 buffer on busy nodes). But its 5sebpfStatsTickercan fire beforeRunhas loaded the eBPF collection, andupdateEbpfStatsAndActiveConnsthen dereferences a nil map:Observed today on prod (0.1.2 rollout): a pod on a burstable spot node (t3.2xlarge) crashed 11 times with exit code 2 — losing the race on every start until the node warmed up — then ran stable. Pre-existing since the ticker was introduced in #219; affects 0.1.0+.
Fix
Tracergets anatomic.Boolready flag, stored afterebpf()loads the collection (the atomic store/load also gives the cross-goroutine happens-before for thecollectionpointer)updateEbpfStatsAndActiveConnsreturns early untiltracer.Ready()— it runs again 5s later, so nothing is lostOther iterator callers were audited: only
updateEbpfStatsAndActiveConnstouches collection maps from outside the tracer's own lifecycle.