-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
WebFlux Blocking controller runs on non-blocking thread when request input data present #32502
Comments
We do have a bit of a hacky workaround which seems to work functionally so developers can continue, but we hope to not have to go into production with this. The workaround is to create a if (shouldOffload(handlerMethod)) {
final MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
for (int i = 0; i < methodParameters.length; i++) {
final HandlerMethodArgumentResolver resolver = findArgRequiringOffloading(methodParameters[i]);
if (resolver != null) {
// Wrap any method parameters that must be resolved in a blocking manner
methodParameters[i] = new BlockingMethodParameter(methodParameters[i], ...);
}
}
} Then create a @Override
public boolean supportsParameter(final MethodParameter parameter) {
return parameter instanceof BlockingMethodParameter;
}
@Override
public Mono<Object> resolveArgument(final MethodParameter param, final BindingContext bindingContext, final ServerWebExchange exchange) {
if (param instanceof BlockingMethodParameter) {
return actualArgumentResolver.resolveArgument(...)
.publishOn(offloadScheduler);
}
} |
Indeed, the resolving of arguments causes a thread hop to the netty thread because the And testament to that, your workaround uses an explicit We should find a way to do something equivalent directly in |
Sounds good to me. I'm happy to try out a snapshot when one becomes available. |
@blake-bauman, a new Spring Framework |
Looks good! I'm getting this now with
|
When configuring Blocking Execution and using a blocking endpoint, the request does not get properly offloaded when request input is available.
Versions:
Sample Code
Here is a sample controller with a GET and a POST.
If you make a call to
GET /api/get
, the response will be 200 with a thread name similar totask-1
. If you make a call toPOST /api/post
with any JSON request body such at{"foo":"bar"}
the response will be a 500 with a thread name similar toreactor-http-nio-5
.Expected Results
I would expect both blocking endpoints to be running on a blocking-safe thread.
Notes
I've attached a gzip of a simple application generated from start.spring.io which registers a
WebFluxConfigurer
to configure aBlockingExecutionConfigurer
and has the above controller:The text was updated successfully, but these errors were encountered: