Skip to content

Commit bb5be21

Browse files
committed
Restore exception phrase in DisconnectedClientHelper
Effectively revert 203fa7, and add implementation comment and tests. See gh-34264
1 parent cf66236 commit bb5be21

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/util/DisconnectedClientHelper.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -36,8 +36,11 @@
3636
*/
3737
public class DisconnectedClientHelper {
3838

39+
// Look for server response connection issues (aborted), not onward connections
40+
// to other servers (500 errors).
41+
3942
private static final Set<String> EXCEPTION_PHRASES =
40-
Set.of("broken pipe", "connection reset");
43+
Set.of("broken pipe", "connection reset by peer");
4144

4245
private static final Set<String> EXCEPTION_TYPE_NAMES =
4346
Set.of("AbortedException", "ClientAbortException",
@@ -79,7 +82,6 @@ else if (logger.isDebugEnabled()) {
7982
* <li>ClientAbortException or EOFException for Tomcat
8083
* <li>EofException for Jetty
8184
* <li>IOException "Broken pipe" or "connection reset by peer"
82-
* <li>SocketException "Connection reset"
8385
* </ul>
8486
*/
8587
public static boolean isClientDisconnectedException(Throwable ex) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.util;
18+
19+
import java.io.EOFException;
20+
import java.io.IOException;
21+
import java.util.List;
22+
23+
import org.apache.catalina.connector.ClientAbortException;
24+
import org.eclipse.jetty.io.EofException;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.MethodSource;
28+
import org.junit.jupiter.params.provider.ValueSource;
29+
import reactor.netty.channel.AbortedException;
30+
31+
import org.springframework.web.context.request.async.AsyncRequestNotUsableException;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
/**
36+
* Unit tests for {@link DisconnectedClientHelper}.
37+
* @author Rossen Stoyanchev
38+
*/
39+
public class DisconnectedClientHelperTests {
40+
41+
@ParameterizedTest
42+
@ValueSource(strings = {"broKen pipe", "connection reset By peer"})
43+
void exceptionPhrases(String phrase) {
44+
Exception ex = new IOException(phrase);
45+
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue();
46+
47+
ex = new IOException(ex);
48+
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue();
49+
}
50+
51+
@Test
52+
void connectionResetExcluded() {
53+
Exception ex = new IOException("connection reset");
54+
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isFalse();
55+
}
56+
57+
@ParameterizedTest
58+
@MethodSource("disconnectedExceptions")
59+
void name(Exception ex) {
60+
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue();
61+
}
62+
63+
static List<Exception> disconnectedExceptions() {
64+
return List.of(
65+
new AbortedException(""), new ClientAbortException(""),
66+
new EOFException(), new EofException(), new AsyncRequestNotUsableException(""));
67+
}
68+
69+
}

0 commit comments

Comments
 (0)