Open Alex100 opened 3 years ago
I understand there may be some use cases impacted here but using ServerRequestContext.currentRequest<HttpRequest<*>>().orElse(null)
should never be done in a controller method like your example. You can simply inject the request into the method and use it.
This is only a minimal working example that reproduces the problem. In our real use case, we use HttpResponse.ok()
in a HttpClientFilter
. The underlying AWS implementation of HttpResponseFactory
calls then ServerRequestContext.currentRequest()
(see: https://github.com/micronaut-projects/micronaut-aws/blob/222f6025a66500d692ba1de570de8f186993df0d/function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/model/factory/MicronautAwsProxyResponseFactory.java line 56).
Using coroutines with Micronaut and AWS Lambdas enforced us to scope controller functions with
runBlocking
(see discussion https://github.com/micronaut-projects/micronaut-aws/issues/1079). This results in a problem where thecurrentRequest
is null ifServerRequestContext.currentRequest()
is called in the inner block ofrunBlocking
andasync(Dispatchers.IO)
Task List
Steps to Reproduce
curl http://localhost:8080/test
Expected Behaviour
success|success in 1002 ms
Actual Behaviour
fail|fail in 1002 ms
Environment Information