prevent "docker stats" from hanging if the initial API call fails #4730
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.
When running
docker stats
without a list of containers,runStats
collects an initial list of containers. If that API call fails, the error is sent to thecloseChan
, however,closeChan
is non-buffered, and nothing is reading the channel until we received the initial list and start collecting stats.This patch rewrites the code that gets the initial list of containers to return the error if the API call fails. The
getContainerList
closure is also removed and inlined to make the logic somewhat easier to read.Before this patch, the command would hang without producing output;
With this patch, the error is printed, and the CLI exits:
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)