Skip to content

fix(agent): initialize SnapshotCache resource maps to avoid nil-map panic - #73

Merged
bpalermo merged 1 commit into
mainfrom
fix/agent-snapshotcache-nil-maps
Jun 7, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/agent-snapshotcache-nil-maps

Conversation

@bpalermo

@bpalermo bpalermo commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Problem

The agent panics with assignment to entry in nil map on restart when pods already exist in local storage:

panic: assignment to entry in nil map
  cache.(*SnapshotCache).LoadListenersFromStorage  listener.go:113
  server.(*AgentXdsServer).PreListen               server.go:70

LoadListenersFromStorage assigns to c.listeners without a lazy nil-init (unlike AddPod, which guards it). PreListen runs it before any AddPod, so on a restart with persisted pods the map is still nil. It stayed latent because agents previously started with empty local storage, and the unit tests masked it by pre-initializing the map via a helper.

Surfaced deploying the merged agent to talos-main: the node that already had managed pods (echo/client) crash-looped, while empty nodes came up fine.

Fix

Initialize listeners, clusters, and secrets in NewSnapshotCache so no path can assign to a nil map. Adds a regression test that loads pods into a freshly constructed cache (no manual init).

…anic

LoadListenersFromStorage assigns to c.listeners without a lazy nil-init (unlike
AddPod), so the agent panicked with "assignment to entry in nil map" on restart
when pods already existed in local storage — PreListen loads them before any
AddPod runs. It stayed latent because agents previously started with empty
storage, and the unit tests pre-initialized the map via a helper.

Initialize the listeners, clusters, and secrets maps in NewSnapshotCache so no
code path can assign to a nil map. Add a regression test that loads pods into a
freshly constructed cache without manual map init.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bpalermo
bpalermo merged commit 4e40ed3 into main Jun 7, 2026
10 checks passed
@bpalermo
bpalermo deleted the fix/agent-snapshotcache-nil-maps branch June 7, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant