-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cli/command/container: RunStats: simplify, and fix context-cancellation #6582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Use a single select for the ticker and the closeChan; use early returns. Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
051ccb2 to
e01ce69
Compare
|
Thanks @robmry ! |
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)