events: logfile backend drops historical events when --until is in the past
Issue Description
When using the file-based events backend (events_logger = "file" in containers.conf), invoking podman events with an --until option set to a timestamp or relative duration in the past (e.g. --until 10m or --until 2025-01-01T00:00:00) causes the tail reader to terminate immediately before historical events can be read from events.log.
In libpod/events/logfile.go (EventLogFile.Read):
if len(options.Until) > 0 {
untilTime, err := util.ParseInputTime(options.Until, false)
if err != nil {
return err
}
go func() {
time.Sleep(time.Until(untilTime))
if err := t.Stop(); err != nil {
logrus.Errorf("Stopping logger: %v", err)
}
}()
}
When untilTime is in the past:
time.Until(untilTime) evaluates to a negative time.Duration.
In Go, time.Sleep(d) returns immediately when d <= 0.
The background goroutine immediately invokes t.Stop().
t.Stop() closes the t.Lines channel concurrently as the event reading loop is starting, prematurely aborting event collection from disk.
Additionally, when untilTime is in the future, the spawned goroutine sleeps without selecting on ctx.Done(), causing a goroutine leak if the client cancels the context early.
Steps to reproduce the issue
Steps to reproduce the issue
- Configure Podman to use file-based event logging by adding to
containers.conf:
[engine]
events_logger = "file"
- Generate container events (e.g., run
podman run --rm alpine truemultiple times). - Query historical events with a past
--untilboundary
podman events --stream=false --since 1h --until 1m
Describe the results you received
No events are printed to stdout (or the output is prematurely terminated after reading 0–1 lines) because t.Stop() closes the tail channel immediately upon startup.
Describe the results you expected
Podman should parse the event log and output all recorded events that occurred between --since and --until.
podman info output
host:
arch: amd64
buildahVersion: 1.40.0
conmon:
package: conmon-2.1.12-1.fc41.x86_64
path: /usr/bin/conmon
version: 'conmon version 2.1.12, commit: '
distribution:
distribution: fedora
version: "41"
eventsLogger: file
ociRuntime:
name: crun
package: crun-1.20-1.fc41.x86_64
path: /usr/bin/crun
version: crun version 1.20
os: linux
Podman in a container
No
Privileged Or Rootless
Rootless
Upstream Latest Release
Yes
Additional environment details
Occurs on any OS/environment using events_logger = "file" (including rootless Linux, macOS remote, and containerized Podman setups).
Additional information
- Code location:
libpod/events/logfile.go(around lines 119–130) - The event filter
generateEventUntilOptioninlibpod/events/filters.goalready filters out events occurring afteruntilTime. Terminating the reader stream should be synchronized with reading through events rather than an uncoordinated background timer killingtail.Tail.
I am working on a fix and unit test for this in libpod/events/logfile.go and will submit a PR shortly.
A friendly reminder that this issue had no activity for 30 days.
/assign