Skip to content
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

prevent "docker stats" from hanging if the initial API call fails #4730

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

thaJeztah
Copy link
Member

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 the closeChan, 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;

docker stats
# hangs; no output

With this patch, the error is printed, and the CLI exits:

docker stats
Error response from daemon: some error occurred

echo $?
1

- 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)

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 the
`closeChan`, 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;

    docker stats
    # hangs; no output

With this patch, the error is printed, and the CLI exits:

    docker stats
    Error response from daemon: some error occurred

    echo $?
    1

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah merged commit 05a2dc4 into docker:master Dec 20, 2023
76 checks passed
@thaJeztah thaJeztah deleted the fix_stats_hang branch December 20, 2023 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants