micronaut-core
micronaut-core copied to clipboard
Server request not available when controller binding parameter from json
Expected Behavior
In controller parameter's constructor server request should be available via ServerRequestContext.currentRequest()
Actual Behaviour
When body payload is large, sometimes server request is not available via ServerRequestContext.currentRequest()
.
It was working in Micronaut 3.1.4. In that version, server request was always available in parameter constructor. Now with Micronaut 4.3.7, when request payload is small it's always available but when the request payload is large, in the first request after server is started, server request is not available in parameter constructor. In subsquent requests, even the payload is large (the same request) the server request becomes available.
In order the reproduce the behaviour, you should start/restart the server and make the first request with large payload.
You can find example requests in the reproducer project's README.
Steps To Reproduce
- Clone reproducer project from https://github.com/kamer/micronaut-server-request.
- Follow steps in README.
Environment Information
- Arch Linux (
6.7.8-arch1-1
) - java 21.0.1 2023-10-17 Java(TM) SE Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)
Example Application
https://github.com/kamer/micronaut-server-request
Version
4.3.7
Here's additional info.
- I cannot reproduce this in Micronaut Core 4.2.4. It starts with 4.3.0. Commits between versions are here.
- I wanted to compare a working request (first request after server is up) and a not working request (following requests). You can find below. Maybe it helps.
If anyone gives a hint, I can debug further and try to create a pull request if needed.
+1
Not sure if it helps or not but while debugging it seems to only happen when the DelayedExecutionFlow is used. When it's not used it works just fine.
The context is available on the controller, just not on the model. My use-case where I'm finding the issue is when trying to access the context from a Serde singleton.
@kamer Quick fix above if you'd like to use.
@graemerocher @sdelamo Still not quite sure why but when the request is large and a DelayedExecutionFlow is used, the context isn't propagated. My quick fix is to simply propagate the context by adding it on the bindFullBody method since the request is available there and just isn't being propagated already. Might not be a good fix but it gets the job done since this bug is has pretty nasty consequences for my use-case.