Repository navigation
internal/oom: Fix memory leak by removing watcher from map on Stop - #13856
Conversation
3a6eb20 to
4a00fb0
Compare
| if exist { | ||
| delete(ows.watchers, cid) | ||
| } |
There was a problem hiding this comment.
nit; no need to check if it exists before deleting.
| if exist { | |
| delete(ows.watchers, cid) | |
| } | |
| delete(ows.watchers, cid) |
4a00fb0 to
97c9ede
Compare
fuweid
left a comment
There was a problem hiding this comment.
THANKS. Left one minor suggestion
| require.NoError(t, err) | ||
|
|
||
| // A dummy process to get a valid pid and cgroup | ||
| cmd := exec.Command("sleep", "10") |
There was a problem hiding this comment.
| cmd := exec.Command("sleep", "10") | |
| cmd := exec.Command("sleep", "10000") |
|
Thanks for the reviews. I've applied both of your suggestions. |
|
@HarshalPatel1972 could you please squash commits into one? thanks |
|
@fuweid could use your thoughts on #13853 (comment) and the comment before it as well; not sure what's best |
The oomWatchers.Stop method stopped the watcher but never removed it from the watchers map. Because Add is the only writer and nothing ever deletes from the map, *watcher entries accumulated for the lifetime of the shim process. This resulted in an unbounded memory leak. Furthermore, this prevented the same container ID from ever being watched again if it was re-created, silently dropping OOM monitoring. This commit modifies Stop to delete(ows.watchers, cid), ensuring the watcher is released and the container ID is freed. Signed-off-by: Harshal Patel <[email protected]>
e0209f9 to
7f94556
Compare
|
@fuweid Done. Commits are squashed. |
@thaJeztah well, I would like to remove it and close it. Currently, |
|
/cherry-pick release/2.3 |
|
@fuweid: new pull request created: #13870 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
The
oomWatchers.Stopmethod stopped the watcher but never removed it from thewatchersmap. BecauseAddis the only writer and nothing ever deletes from the map,*watcherentries accumulated for the lifetime of the shim process. This resulted in an unbounded memory leak.Furthermore, this prevented the same container ID from ever being watched again if it was re-created, silently dropping OOM monitoring.
This commit modifies
Stoptodelete(ows.watchers, cid), ensuring the watcher is released and the container ID is freed. It also adds a unit test inwatcher_test.goto ensureStopsuccessfully allows a watcher to be re-added under the same container ID.