fix httpclient5.x connection leak
Signed-off-by: jiangyuan <joe469391363@gmail.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.gateway.server.mvc.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -75,6 +76,7 @@ public abstract class RetryFilterFunctions {
|
||||
if (config.isCacheBody()) {
|
||||
MvcUtils.getOrCacheBody(request);
|
||||
}
|
||||
reset(request);
|
||||
ServerResponse serverResponse = next.handle(request);
|
||||
|
||||
if (isRetryableStatusCode(serverResponse.statusCode(), config)
|
||||
@@ -86,6 +88,20 @@ public abstract class RetryFilterFunctions {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* reset attribute
|
||||
*
|
||||
* @param request
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void reset(ServerRequest request) throws IOException {
|
||||
InputStream inputStream = MvcUtils.getAttribute(request, MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR);
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
MvcUtils.putAttribute(request, MvcUtils.CLIENT_RESPONSE_INPUT_STREAM_ATTR, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRetryableStatusCode(HttpStatusCode httpStatus, RetryConfig config) {
|
||||
return config.getSeries().stream().anyMatch(series -> HttpStatus.Series.resolve(httpStatus.value()) == series);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user