Skip to content

Commit 9230a7d

Browse files
committed
WebAsyncManager handles disconnected client errors
See gh-32042
1 parent 7e53a1f commit 9230a7d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
import org.springframework.util.Assert;
3434
import org.springframework.web.context.request.RequestAttributes;
3535
import org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler;
36+
import org.springframework.web.util.DisconnectedClientHelper;
3637

3738
/**
3839
* The central class for managing asynchronous request processing, mainly intended
@@ -66,6 +67,16 @@ public final class WebAsyncManager {
6667

6768
private static final Log logger = LogFactory.getLog(WebAsyncManager.class);
6869

70+
/**
71+
* Log category to use for network failure after a client has gone away.
72+
* @see DisconnectedClientHelper
73+
*/
74+
private static final String DISCONNECTED_CLIENT_LOG_CATEGORY =
75+
"org.springframework.web.server.DisconnectedClient";
76+
77+
private static final DisconnectedClientHelper disconnectedClientHelper =
78+
new DisconnectedClientHelper(DISCONNECTED_CLIENT_LOG_CATEGORY);
79+
6980
private static final CallableProcessingInterceptor timeoutCallableInterceptor =
7081
new TimeoutCallableProcessingInterceptor();
7182

@@ -370,9 +381,13 @@ private void setConcurrentResultAndDispatch(@Nullable Object result) {
370381
return;
371382
}
372383

384+
if (result instanceof Exception ex && disconnectedClientHelper.checkAndLogClientDisconnectedException(ex)) {
385+
return;
386+
}
387+
373388
if (logger.isDebugEnabled()) {
374-
boolean isError = result instanceof Throwable;
375-
logger.debug("Async " + (isError ? "error" : "result set") + ", dispatch to " + formatRequestUri());
389+
logger.debug("Async " + (this.errorHandlingInProgress ? "error" : "result set") +
390+
", dispatch to " + formatRequestUri());
376391
}
377392
this.asyncWebRequest.dispatch();
378393
}

0 commit comments

Comments
 (0)