cli/command/container: RunStats: simplify, and fix context-cancellation#6582
Merged
thaJeztah merged 7 commits intodocker:masterfrom Oct 28, 2025
Merged
cli/command/container: RunStats: simplify, and fix context-cancellation#6582thaJeztah merged 7 commits intodocker:masterfrom
thaJeztah merged 7 commits intodocker:masterfrom
Conversation
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Use a single select for the ticker and the closeChan; use early returns. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a context-cancellation issue in the docker stats command where it would not exit gracefully when interrupted. The changes simplify the stats collection loop and add proper handling for context cancellation and EOF errors.
Key changes:
- Refactored the stats loop from a
for range ticker.Cpattern to afor { select { ... } }pattern with explicit context cancellation handling - Added early return for non-streaming mode to avoid entering the ticker loop unnecessarily
- Improved error handling to gracefully handle
io.EOFandio.ErrUnexpectedEOF
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cli/command/container/stats_helpers.go | Removed debug log statement from collect function (moved to call-site) |
| cli/command/container/stats.go | Main implementation changes: refactored stats loop, added context cancellation handling, moved debug logs to call-sites, and improved error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Some suggestions from ChatGPT to prevent deadlocks. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
We should consider splitting this out to a separate function, but start with just an early return before we hit the timer-loop. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
0c6d17b to
292001a
Compare
construct the decoder inside the go-routine, including closing the body, and add handling for context-cancellation. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
051ccb2 to
e01ce69
Compare
robmry
approved these changes
Oct 28, 2025
Member
Author
|
Thanks @robmry ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docker stats <container>doesn't exit gracefully #6090cli/command/container: RunStats: simplify, and fix context-cancellation
cli/command/container: move debug logs to call-site
cli/command/container: RunStats: simplify stats loop
Use a single select for the ticker and the closeChan; use early returns.
cli/command/container: RunStats: handle context-cancellation
cli/command/container: RunStats: gracefully handle io.EOF
cli/command/container: RunStats: small tweaks on closeChan
Some suggestions from ChatGPT to prevent deadlocks.
cli/command/container: RunStats: early return for non-streaming
We should consider splitting this out to a separate function, but
start with just an early return before we hit the timer-loop.
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)