Skip to content

manager: fix race condition in Stop() using sync.Once#3803

Merged
dims merged 1 commit into
google:masterfrom
dims:fix-destroy-container-race-sync-once
Dec 19, 2025
Merged

manager: fix race condition in Stop() using sync.Once#3803
dims merged 1 commit into
google:masterfrom
dims:fix-destroy-container-race-sync-once

Conversation

@dims

@dims dims commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator

The switch from RWMutex to sync.Map in commit 20e39fc introduced a race condition in destroyContainer(). When multiple goroutines attempt to destroy the same container simultaneously, they can all call Stop() on the same containerData, causing a "close of closed channel" panic.

The panic manifests as:
panic: close of closed channel
goroutine N [running]:
github.com/google/cadvisor/manager.(*containerData).Stop(...)
manager/container.go:143 +0x46

Fix this by using sync.Once to ensure the stop channel is only closed once, making Stop() safe to call multiple times.

@dims dims force-pushed the fix-destroy-container-race-sync-once branch 2 times, most recently from 0702f11 to 84ddcc3 Compare December 19, 2025 20:07
The switch from RWMutex to sync.Map in commit 20e39fc introduced a
race condition in destroyContainer(). When multiple goroutines attempt
to destroy the same container simultaneously, they can all call Stop()
on the same containerData, causing a "close of closed channel" panic.

The panic manifests as:
  panic: close of closed channel
  goroutine N [running]:
  github.com/google/cadvisor/manager.(*containerData).Stop(...)
          manager/container.go:143 +0x46

Fix this by using sync.Once to ensure the stop channel is only closed
once, making Stop() safe to call multiple times.

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
@dims dims force-pushed the fix-destroy-container-race-sync-once branch from 84ddcc3 to 6bd8d7d Compare December 19, 2025 20:14
@dims dims merged commit f5bec37 into google:master Dec 19, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant