events: fix goroutine leak when using --until with dropped contexts - #29499
Conversation
When fetching events with the --until flag on a system using the file events backend, libpod/events/logfile.go spawned an unmanaged goroutine running time.Sleep(time.Until(untilTime)). Because time.Sleep is not context-aware, if a client cancelled the request or dropped the connection, the goroutine remained sleeping in the background for the full until duration. Fix this by using time.NewTimer and selecting on ctx.Done() so the background goroutine exits immediately when the context is cancelled. Fixes: podman-container-tools#29491 Signed-off-by: Harsha Vardhan <harshahvk2005@gmail.com>
| require.Equal(t, beforeRename, afterRename) | ||
| } | ||
|
|
||
| func TestReadUntilContextCancelled(t *testing.T) { |
There was a problem hiding this comment.
This unit test doesn't add value, please remove
|
Thanks @mheon. I've removed the redundant |
Remove the redundant context cancellation test as requested during review. Fixes: podman-container-tools#29491 Signed-off-by: Harsha Vardhan <harshahvk2005@gmail.com>
e1e4f01 to
f7caec8
Compare
|
Hi @Honny1, I’ve addressed the review feedback by removing the redundant The changes are now pushed and the CI checks are running. Once CI completes successfully, this should be ready for merge. Thanks for the review! |
Honny1
left a comment
There was a problem hiding this comment.
LGTM
PTAL @podman-container-tools/podman-reviewers @podman-container-tools/podman-maintainers
|
@KHARSHAVARDHAN-eng PR needs a second review. |
Fixes #29491
When fetching events with
--untilon a system using the file events backend,libpod/events/logfile.gospawned an unmanaged goroutine runningtime.Sleep(time.Until(untilTime)). Becausetime.Sleepignorescontext.Contextcancellation, early client disconnects (or Ctrl+C) caused the sleeping goroutine to remain alive for the fulluntilduration.Changes
time.Sleepwith atime.NewTimerandselectstatement listening onctx.Done(), ensuring the wait exits immediately when the context is cancelled.TestReadUntilContextCancelledtest as requested during review.