Skip to content

events: fix goroutine leak with until flag in file backend - #29493

Draft
HindzStark wants to merge 1 commit into
podman-container-tools:mainfrom
HindzStark:fix-event-until-leak
Draft

events: fix goroutine leak with until flag in file backend#29493
HindzStark wants to merge 1 commit into
podman-container-tools:mainfrom
HindzStark:fix-event-until-leak

Conversation

@HindzStark

Copy link
Copy Markdown

- What I did
Fixed a goroutine and memory leak in the file events backend when using the --until flag.

Previously, libpod/events/logfile.go spawned an unmanaged goroutine using time.Sleep(time.Until(untilTime)) that ignored context.Context cancellation. If a client disconnected early (e.g. dropped API connection or Ctrl+C), the goroutine was orphaned and continued sleeping in the background.

I replaced the blocking time.Sleep with a time.NewTimer and a select block that listens for ctx.Done(). This ensures the goroutine exits immediately if the client cancels the request, properly freeing system resources and preventing an API denial-of-service vector.

- How I did it

  • Replaced time.Sleep with time.NewTimer.
  • Added a select statement listening to <-ctx.Done() and <-timer.C.

- How to verify it

  1. Run podman system service
  2. Fetch events via the API with a far-future until parameter: curl -v --unix-socket /run/user/1000/podman/podman.sock "http://d/v4.0.0/libpod/events?until=9999h"
  3. Terminate the curl request (Ctrl+C).
  4. Verify via pprof or logging that the background routine is destroyed and no longer sleeping.

- Description for the changelog

Fixed a goroutine leak in the event logger that occurred when an event stream using the `--until` flag was prematurely cancelled by the client.

**- Fixes** 
Fixes #29491

Signed-off-by: dhruv <dhruvdkjk@gmail.com>
@HindzStark
HindzStark force-pushed the fix-event-until-leak branch from 2cec10d to 5cec7d6 Compare August 13, 2026 09:49
@Honny1

Honny1 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

We have been getting a lot of low quality PRs that do not follow our contribution guidelines and LLM policy. Because our time is limit I reserve the right to just close these PRs without further comments.

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.

2 participants