generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Function Server TCK: Body has already been consumed exception #921
Labels
type: improvement
A minor improvement to an existing feature
Comments
andriy-dmytruk
changed the title
Function Server TCK: Body has already been consume exception
Function Server TCK: Body has already been consumed exception
Jun 11, 2024
Hmm, perhaps it is the same issue as here: micronaut-projects/micronaut-servlet#548 |
I think changes similar to https://github.com/micronaut-projects/micronaut-gcp/pull/1106/files will probably need to be implemented. @yawkat should confirm. |
graemerocher
pushed a commit
that referenced
this issue
Jun 18, 2024
This PR adds Micronaut Server TCK for Oracle Cloud Function HTTP. Currently, 10 of 188 tests (5%) fail. Fixes: * Making the request implementation mutable to support filters. * Allow empty response when an exception is thrown micronaut-servlet#737 * Add support for parsing form data and support empty values in the form data. * Support binding publisher when there is only one element. * Support binding body parts for JSON case (so binding JSON properties). * Fix reading cookies from headers. Created issues: Function Server TCK: Body has already been consumed exception #921 Function Server TCK: ControllerConstraintHandlerTest failing because of getBody() #925 Function Server TCK: RequestFilterTest failing #926
graemerocher
pushed a commit
that referenced
this issue
Jun 24, 2024
The proposed approach to do the same as in micronaut-projects/micronaut-gcp#1106 did not exactly work. This is because the `InputEvent` does not allow accessing the `InputStream` directly. Instead it has a method `consumeBody(Function<InputStream>)` that should be called with implementation similar to this: ```java <T> T consumeBody(Function<InputStream, T> function) { /* verify that not null and not opened twice ... */ try { return function.call(this.body); } finally { this.body.close(); } /* ... */ } ``` Because it closes the stream we cannot read the stream gradually and split it. The solution is to read the stream as a whole into a byte array and then provide it to all the consumers. This will probably result in the same memory usage as in https://github.com/micronaut-projects/micronaut-gcp/pull/1106/files (since there we split each time and end up with one unused ByteBody caching the whole request). However, it will require reading the whole body before it is consumed (e.g. JSON parser cannot begin parsing the stream before whole body is read into memory). --------- Co-authored-by: micronaut-build <65172877+micronaut-build@users.noreply.github.com> Co-authored-by: yawkat <jonas.konrad@oracle.com>
graemerocher
added
the
type: improvement
A minor improvement to an existing feature
label
Jun 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue description
Description
The Server TCK was added in this PR: #920.
Currently the io.micronaut.http.server.tck.tests.LocalErrorReadingBodyTest#jsonSyntaxErrorBodyAccessible test is failing in tck.
The original cause of the exception seems to be the one below. The body input stream is read twice for some reason. An alternative InputEvent implementation can be created instead of the ReadOnceInputEvent, but it does not seem like a good idea since we don't know which event will be produced in production.
The test has the following method:
and following calls:
Reproduce
The issue can be reproduced by running the TCK and putting a breakpoint on
ServletHttpHandler#service
line 225.The exception that is currently shown as a result is
but this seems to only be an issue with displaying the correct error in logs. When using fix in micronaut-projects/micronaut-servlet#737 the "Body has already been consumed" exception is shown instead.
cc @yawkat
The text was updated successfully, but these errors were encountered: