mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
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:
+6
-7
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user