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

Allow empty body in POST /commit again #45550

Merged
merged 2 commits into from May 18, 2023

Conversation

corhere
Copy link
Contributor

@corhere corhere commented May 17, 2023

- What I did
Fixed a regression in the POST /commit API endpoint which made it an error to not include a JSON body in the request. This regression went unnoticed because a bug in the client caused it to always send a request body of

null

when options.Config == nil.

- How I did it
I changed runconfig.loadJSON to return an error which wraps the error from the JSON decoder so that the caller can once again test whether the error is io.EOF.

I modified the client to treat typed-nil request objects the same as untyped nil: a signal that the request should not have a body. This may be a controversial change as it will break client compatibility with buggy daemons, though I feel it is necessary for the long-term health of the project. The regression snuck in because the quirks of the client let it go unnoticed; making the client less quirky forces us to not become dependent on those quirks. (I also want to see what else a full CI run with this client change reveals.)

- How to verify it
Existing integration tests fail after the first commit, and pass after the second.

- Description for the changelog

  • Fixed a regression in POST /commit which made it an error to make a request with no body.

- A picture of a cute animal (not mandatory but encouraged)

The internal Client request methods which accept an object as a body use
nil to signal that the request should not have a body. But it is easy to
accidentally pass a typed-nil value as the object, e.g. if the object
comes from a function argument or struct field of a concrete type. The
result is that these requests will, surprisingly, have a JSON body of
`null`. Treat typed-nil pointers the same as untyped nils for the
purposes of determining whether or not the request should include a
body.

Stop assuming that POST requests should always have a body. POST /commit
does not require a body, for example.

Signed-off-by: Cory Snider <csnider@mirantis.com>
The error returned by DecodeConfig was changed in
b6d58d7 and caused this to regress.
Allow empty request bodies for this endpoint once again.

Signed-off-by: Cory Snider <csnider@mirantis.com>
@corhere corhere added the kind/bugfix PR's that fix bugs label May 17, 2023
@corhere corhere added this to the 25.0.0 milestone May 17, 2023
@thaJeztah
Copy link
Member

The result is that these requests will, surprisingly, have a JSON body of
null.

🙈😂

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

discused; we can backport the server-side changes, and leave the client improvements for v25 and up

@thaJeztah thaJeztah merged commit 1b3c274 into moby:master May 18, 2023
93 of 94 checks passed
@corhere corhere deleted the fix-empty-container-decode branch May 18, 2023 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker commit REST API error: {"message":"invalid JSON: got EOF while reading request body"}
3 participants