RetryableFeignBlockingLoadBalancerClient closes stream and makes response content unavailable
When RetryableFeignBlockingLoadBalancerClient activates, closes and losts response content When is ignored, response content is available
Bug exists at least in 2.2.8.RELEASE
https://github.com/spring-cloud/spring-cloud-openfeign/blob/main/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java#L164
if (retryPolicy != null && retryPolicy.retryableStatusCode(responseStatus)) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Retrying on status code: %d", responseStatus));
}
response.close(); // that is the point
throw new RetryableStatusCodeException(serviceId, responseStatus, response, URI.create(request.url()));
}
Affected code: https://github.com/OpenFeign/feign/blob/10.12/core/src/main/java/feign/Logger.java#L99
byte[] bodyData = Util.toByteArray(response.body().asInputStream()); // here IOException
bodyLength = bodyData.length;
if (logLevel.ordinal() >= Level.FULL.ordinal() && bodyLength > 0) {
log(configKey, "%s", decodeOrDefault(bodyData, UTF_8, "Binary data"));
}
https://github.com/OpenFeign/feign/blob/10.12/core/src/main/java/feign/FeignException.java#L156
byte[] body = {};
try {
if (response.body() != null) {
body = Util.toByteArray(response.body().asInputStream()); // here IOException
}
} catch (IOException ignored) { // NOPMD
}
Sample Without retrying, feign logs level full looks like
{"timestamp":"2021-07-01T11:25:45.782Z","status":500,"error":"Internal Server Error","message":"","path":"/foo/bar"} <--- END HTTP (141-byte body)
With retry, they looks
] <--- ERROR IOException: stream is closed (660ms) java.io.IOException: stream is closed
Additionally, response content is or is not part of FeignException, depending on retrying