Skip to content

WebFlux Blocking controller runs on non-blocking thread when request input data present #32502

@blake-bauman

Description

@blake-bauman

When configuring Blocking Execution and using a blocking endpoint, the request does not get properly offloaded when request input is available.

Versions:

  • Spring Boot 3.2.3
  • Spring Framework: 6.1.4
  • Java: 21

Sample Code

Here is a sample controller with a GET and a POST.

@RestController @RequestMapping("/api") public class DemoController { private static final Logger LOGGER = LoggerFactory.getLogger(DemoController.class); @GetMapping(value = "/get", produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> methodBlockingWithRequestBody() { return testSafeBlockingThread(); } @PostMapping(value = "/post", consumes = APPLICATION_JSON_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> methodBlockingWithRequestBody(@RequestBody final Map<String, String> data) { return testSafeBlockingThread(); } private ResponseEntity<String> testSafeBlockingThread() { final String threadName = Thread.currentThread().getName(); if (Schedulers.isInNonBlockingThread()) { LOGGER.error("Non-blocking thread: {}", threadName); return ResponseEntity.internalServerError().body("Non-blocking thread: " + threadName); } LOGGER.info("Blocking-safe thread: {}", threadName); return ResponseEntity.ok("Blocking-safe thread: " + threadName); } }

If you make a call to GET /api/get, the response will be 200 with a thread name similar to task-1. If you make a call to POST /api/post with any JSON request body such at {"foo":"bar"} the response will be a 500 with a thread name similar to reactor-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 a BlockingExecutionConfigurer and has the above controller:

Metadata

Metadata

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions