You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
internal/oom: Stop never removes the watcher from the map, leaking watchers and burning container IDs #13853
Add is the only writer of that map and nothing ever deletes from it, so entries accumulate for the lifetime of the shim process. Two consequences:
1. Stopped watchers are leaked. Every container that exits leaves a stopped *watcher behind, holding a cid, a cgroupPath, an *os.File and a channel. stop() does close the event FD, so this is a memory leak rather than an FD leak, but it is unbounded in the number of containers the shim has ever run.
2. A container ID can never be watched twice.Add rejects an ID that is already in the map with errdefs.ErrAlreadyExists. Once a container ID has been stopped it can never be added again in the same shim, so a container re-created under that ID silently runs with no OOM monitoring — the Create path only logs the failure:
Both matter because a shim is grouped per sandbox (manager_linux.go groups by io.kubernetes.cri.sandbox-id), so one shim process hosts every container of a pod, across restarts, for the pod's whole lifetime.
The only production caller is cmd/containerd-shim-runc-v2/task/service.go: Add in the create path, Stop in handleProcessExit.
Steps to reproduce
Directly observable as a unit test in internal/oom:
While looking into the fix, I realized it's not as simple as it looks. If we remove the entry before w.stop(), a concurrent Add can sneak in while the old goroutine is still shutting down - which could briefly run two watchers for the same container. If we remove it after w.stop() returns, it's safer but a ~concurrent Add for the same container ID will get ErrAlreadyExists until the goroutine fully exits, and cleanup is also delayed if w.stop() takes longer than expected.
I think this needs a call from the maintainers on which tradeoff is acceptable. Closing the PR for now, happy to reopen once there's some clarity on the approach.
Heh; I saw @HarshalPatel1972 just opened #13856 and I was about to comment "should it be removed before Close returns successfully?" but I didn't, and not realizing the other related ticket.
Activity
gautamrizwani commentedon Jul 26, 2026
While looking into the fix, I realized it's not as simple as it looks. If we remove the entry before
w.stop(), a concurrentAddcan sneak in while the old goroutine is still shutting down - which could briefly run two watchers for the same container. If we remove it afterw.stop()returns, it's safer but a ~concurrentAddfor the same container ID will getErrAlreadyExistsuntil the goroutine fully exits, and cleanup is also delayed ifw.stop()takes longer than expected.I think this needs a call from the maintainers on which tradeoff is acceptable. Closing the PR for now, happy to reopen once there's some clarity on the approach.
thaJeztah commentedon Jul 26, 2026
Heh; I saw @HarshalPatel1972 just opened #13856 and I was about to comment "should it be removed before Close returns successfully?" but I didn't, and not realizing the other related ticket.
So ... yes, possibly more logic is needed 🤔