Skip to content

Commit ae7891e

Browse files
committed
Revise disconnected client error handling in WebFlux
A disconnected client error does not necessarily prevent us from setting the status of the WebFlux ServerHttpResponse, which is only gated by a committed flag and does not necessarily reflect the connection state. This is why we need to check if we have a disconnected client error first and handle it accordingly. We still set the response to 500 in case the disconnect client error is to a remote host in which case it will propagate to the client. Closes gh-36811
1 parent 98ed1df commit ae7891e

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,14 @@ private Mono<Void> handleUnresolvedError(
362362
ServerHttpResponse response = exchange.getResponse();
363363
String logPrefix = exchange.getLogPrefix();
364364

365-
// Sometimes a remote call error can look like a disconnected client.
366-
// Try to set the response first before the "isDisconnectedClient" check.
367-
368-
if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {
369-
logger.error(logPrefix + "500 Server Error for " + formatRequest(request), ex);
365+
if (disconnectedClientHelper.checkAndLogClientDisconnectedException(ex)) {
366+
// Attempt to send 500 in case of onward (rather than client) connection issue
367+
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
368+
observationContext.setConnectionAborted(true);
370369
return Mono.empty();
371370
}
372-
else if (disconnectedClientHelper.checkAndLogClientDisconnectedException(ex)) {
373-
observationContext.setConnectionAborted(true);
371+
else if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {
372+
logger.error(logPrefix + "500 Server Error for " + formatRequest(request), ex);
374373
return Mono.empty();
375374
}
376375
else {

0 commit comments

Comments
 (0)