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
This commit is contained in:
rstoyanchev
2026-06-04 11:10:58 +01:00
parent 98ed1dfcf8
commit ae7891e797
@@ -362,15 +362,14 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
ServerHttpResponse response = exchange.getResponse();
String logPrefix = exchange.getLogPrefix();
// Sometimes a remote call error can look like a disconnected client.
// Try to set the response first before the "isDisconnectedClient" check.
if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {
logger.error(logPrefix + "500 Server Error for " + formatRequest(request), ex);
if (disconnectedClientHelper.checkAndLogClientDisconnectedException(ex)) {
// Attempt to send 500 in case of onward (rather than client) connection issue
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
observationContext.setConnectionAborted(true);
return Mono.empty();
}
else if (disconnectedClientHelper.checkAndLogClientDisconnectedException(ex)) {
observationContext.setConnectionAborted(true);
else if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {
logger.error(logPrefix + "500 Server Error for " + formatRequest(request), ex);
return Mono.empty();
}
else {