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
client: improve error messaging on crash #44739
Conversation
client/container_wait.go
Outdated
// | ||
// If there's a JSON parsing error, read the real error message | ||
// off the body and send it to the client. | ||
_, _ = io.ReadAll(stream) |
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.
Maybe wrap stream
with io.LimitReader
(N=a few MiB)
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.
Ya, that's a good callout. i don't think we even need multiple MB, multiple KB will do. Unless there's a reason to preserve error messages a few MB long? added!
This is a bit similar to containerd/containerd#4672, and a similar discussion about "what to return" on the PR to address that; containerd/containerd#7564 Some questions / quick thoughts I have;
|
Re: is this only for this specific endpoint? Maybe? The /wait endpoint might be the only one that does streaming in this way? re: perhaps it would be good to have a specific status code: The current endpoint assumes that the HTTP status code is sent before the crash. I like this post from the GRPC people on this general problem: https://carlmastrangelo.com/blog/why-does-grpc-insist-on-trailers, it's more of a protocol design challenge on how you model streaming RPCs on top of HTTP. re: a well-formed JSON error Yeah, I think it would be reasonable to change the proxy to return a JSON-encoded error. But AFAICT, we would have to change the response type. The current response type doesn't have a good way to distinguish between "Errors from the underlying container" and "errors talking to the docker engine" what do you think? re: reading the whole body Ya, that's a good callout. i don't think we even need multiple MB, multiple KB will do. Changed! |
d8ecdcb
to
4e62667
Compare
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.
Tiny nit, and the commits should be squashed down as one just amends the other. Otherwise, LGTM, thank you!
9978851
to
5d29e9e
Compare
Repro steps: - Run Docker Desktop - Run `docker run busybox tail -f /dev/null` - Run `pkill "Docker Desktop" Expected: An error message that indicates that Docker Desktop is shutting down. Actual: An error message that looks like this: ``` error waiting for container: invalid character 's' looking for beginning of value ``` here's an example: docker/for-mac#6575 (comment) After this change, you get an error message like: ``` error waiting for container: copying response body from Docker: unexpected EOF ``` which is a bit more explicit. Signed-off-by: Nick Santos <nick.santos@docker.com>
5d29e9e
to
9900c7a
Compare
@neersighted thanks! squashed them! |
Oh! For some reason this one slipped off my list.
I'll create a tracking issue to look into that. Possibly we need a utility for handling some of this (so that it can be handled consistently).
🤦 yeah I didn't think that suggestion through really. Lost out of sight that we're dealing with streaming endpoint so an 200 Header would already be sent (which also has been source of much confusing). Definitely another area where we need better utilities / SDK for handling these (too easy to use the client "the wrong way").
Heh this made me chuckle: "While the point of this post is not to point fingers" (points finger) Definitely interesting post yes. TIL about Trailers (or perhaps I knew about them but it got lost in memory).
I think it should be possible to disambiguate. While the docker engine API itself may not have that ability (there is no real "upstream", well, to the extend that the "backend" in the daemon is the upstream), in the (Docker Desktop) "proxy" situation, it's the proxy that makes a connection with the actual API; if that fails, it could send the right header (and error-format) instead of sending a HTTP 200 "ok". But again here, we must improve (make it easier to) handle the JSONstream responses, as the "actual" error will be in that response, and handling that it currently rather quirky (the least), and there may be a lot of duplication around handling those. |
ya, i'd definitely support some sort of machinery to handle this parsing consistently. |
- What I did
improve error messaging on crash
- How I did it
Report the original HTTP body in the error message, rather than the JSON decoder error parsing the HTTP body
- How to verify it
Repro steps:
docker run busybox tail -f /dev/null
Expected:
An error message that indicates that Docker Desktop is shutting down.
Actual:
An error message that looks like this:
here's an example:
docker/for-mac#6575 (comment)
After this change, you get an error message like:
which is a bit more explicit.
- Description for the changelog
improve client error messaging on engine crash
- A picture of a cute animal (not mandatory but encouraged)