Skip to content

Restore thread interrupt flag in DefaultMvcResult when catching InterruptedException#36876

Open
leestana01 wants to merge 1 commit into
spring-projects:mainfrom
leestana01:fix-mvcresult-interrupt-flag
Open

Restore thread interrupt flag in DefaultMvcResult when catching InterruptedException#36876
leestana01 wants to merge 1 commit into
spring-projects:mainfrom
leestana01:fix-mvcresult-interrupt-flag

Conversation

@leestana01
Copy link
Copy Markdown
Contributor

@leestana01 leestana01 commented Jun 5, 2026

DefaultMvcResult.awaitAsyncDispatch() catches InterruptedException and returns false without restoring the thread's interrupt status, so the interruption is silently lost.

When InterruptedException is caught without being rethrown, the interrupt status should be reasserted, as the framework already does elsewhere. For example, ConcurrencyThrottleSupport re-interrupts the current thread on the same exception ("Re-interrupt current thread, to allow other threads to react."). This applies the same handling with Thread.currentThread().interrupt() before returning false.

There is no other behavior change: an interruption already makes getAsyncResult(...) throw IllegalStateException via the false return, so this only preserves the interrupt status as it propagates. The added test interrupts the current thread before calling getAsyncResult(...) and verifies the interrupt status is still set afterwards.

… InterruptedException

awaitAsyncDispatch() catches InterruptedException, returns false, and
discards the interruption. Catching InterruptedException without
rethrowing should restore the interrupt status (as is done across the
framework's main sources), so re-assert it before returning false.

Signed-off-by: leestana01 <leestana01@naver.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 5, 2026
@leestana01
Copy link
Copy Markdown
Contributor Author

One note on the test: CountDownLatch.await(...) clears the interrupt status when it throws InterruptedException, so on the current code the assertion Thread.currentThread().isInterrupted() is false. The test therefore fails without the one-line change and passes with it.

@sbrannen sbrannen added in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jun 5, 2026
@sbrannen sbrannen self-assigned this Jun 5, 2026
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 5, 2026
@sbrannen sbrannen added this to the 7.0.8 milestone Jun 5, 2026
@sbrannen sbrannen changed the title DefaultMvcResult does not restore thread interrupt flag when catching InterruptedException Restore thread interrupt flag in DefaultMvcResult when catching InterruptedException Jun 5, 2026
@sbrannen sbrannen modified the milestones: 7.0.8, 7.1.0-M1 Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants