Skip to content

fix(events): treat io.EOF as a normal end of a bounded stream - #14444

Merged
ndeloof merged 2 commits into
docker:mainfrom
Bruce848647703:fix/events-eof-exit-code
Nov 3, 2026
Merged

ndeloof merged 2 commits into
docker:mainfrom
Bruce848647703:fix/events-eof-exit-code

Conversation

@Bruce848647703

Copy link
Copy Markdown
Contributor

Fixes #14442.

Problem

The Engine client sends io.EOF over EventsResult.Err once a stream has been read completely, which is exactly what happens when events --until reaches its deadline:

case err := <-res.Err:
    return err

Service.Events returned that error verbatim, so plugin.Run printed EOF and exited 1 even though every matching event had already been delivered. docker events in docker/cli treats the same io.EOF as success.

Change

Return nil when the stream ends with io.EOF, and keep propagating genuine stream errors.

Tests

Added internal/inspect/events_test.go:

  • a bounded stream that ends with io.EOF completes without an error
  • any other stream error is still returned
go test ./internal/inspect/  ->  ok
gofmt -l                     ->  clean

The unit tests drive Service.Events through the generated MockAPIClient; no Docker daemon is required.

@Bruce848647703
Bruce848647703 requested review from a team as code owners November 3, 2026 12:31
The Engine client sends io.EOF over EventsResult.Err once the stream has
been read completely, which is what happens when `events --until` reaches
its deadline. Service.Events returned that error verbatim, so the command
printed "EOF" and exited 1 even though every event had been delivered.

Return nil for io.EOF and keep propagating real stream errors.

Signed-off-by: Zhuoming Wang <zhuomingwang0901@outlook.com>
@Bruce848647703
Bruce848647703 force-pushed the fix/events-eof-exit-code branch from 45a8d01 to 1266c2a Compare November 3, 2026 12:49
ndeloof
ndeloof previously approved these changes Nov 3, 2026

@ndeloof ndeloof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The fix is correct: the moby client sends io.EOF on EventsResult.Err once the stream is fully read (the Messages channel is unbuffered, so no event can be dropped before it), genuine errors such as io.ErrUnexpectedEOF are still propagated, and this matches docker events.

Only blocker before merge: validate (lint) fails because forbidigo rejects context.Background() in tests (events_test.go:45 and :64). Please use t.Context() instead.

forbidigo rejects context.Background() in tests; t.Context() is the
intended replacement and carries the test's cancellation.

Signed-off-by: Zhuoming Wang <zhuomingwang0901@outlook.com>
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ndeloof
ndeloof merged commit ac8b2cd into docker:main Nov 3, 2026
61 checks passed
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.

[BUG] compose events --until exits 1 with "EOF" when the event window closes

2 participants