Skip to content

Commit b6e8de9

Browse files
committed
fix httpclient5.x connection leak
1 parent a729fc0 commit b6e8de9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/RetryFilterFunctions.java

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.cloud.gateway.server.mvc.filter;
1818

1919
import java.io.IOException;
20+
import java.io.InputStream;
2021
import java.util.Arrays;
2122
import java.util.HashMap;
2223
import java.util.HashSet;
@@ -75,6 +76,7 @@ public static HandlerFilterFunction<ServerResponse, ServerResponse> retry(RetryC
7576
if (config.isCacheBody()) {
7677
MvcUtils.getOrCacheBody(request);
7778
}
79+
reset(request);
7880
ServerResponse serverResponse = next.handle(request);
7981

8082
if (isRetryableStatusCode(serverResponse.statusCode(), config)
@@ -86,6 +88,20 @@ && isRetryableMethod(request.method(), config)) {
8688
});
8789
}
8890

91+
/**
92+
* reset attribute
93+
*
94+
* @param request
95+
* @throws IOException
96+
*/
97+
private static void reset(ServerRequest request) throws IOException {
98+
InputStream inputStream = MvcUtils.getAttribute(request, MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR);
99+
if (inputStream != null) {
100+
inputStream.close();
101+
MvcUtils.putAttribute(request, MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR, null);
102+
}
103+
}
104+
89105
private static boolean isRetryableStatusCode(HttpStatusCode httpStatus, RetryConfig config) {
90106
return config.getSeries().stream().anyMatch(series -> HttpStatus.Series.resolve(httpStatus.value()) == series);
91107
}

0 commit comments

Comments
 (0)