Does not retry "java.io.IOException: Premature EOF" exceptions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
For WIremock's Fault.MALFORMED_RESPONSE_CHUNK Feign's retry mechanisms does not kick in and the exception is thrown without a retry. For Fault.CONNECTION_RESET_BY_PEER the retry mechanism works as expected.
I'm using the default Retryer (feign.Retryer.Default) and a custom ErrorDecoder (both are not invoked)
I've noticed the org.springframework.cloud.openfeign.support.SpringDecoder class mentioned in the stacktrace, if you think that this issue belongs to Spring Cloud Open Feign, I'm happy to move it there.
My test case is similar to this:
stubFor(get(urlPathEqualTo("/test-url"))
.inScenario("retry test")
.willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK))
.willSetStateTo("failed once"));
stubFor(get(urlPathEqualTo("/test-url"))
.inScenario("retry test")
.whenScenarioStateIs("failed once")
.willReturn(okJson(fromFile("response.json"))));
var response = feignClient.getTestUrl();
assertThat(response).isPresent();
verify(exactly(2), getRequestedFor(urlPathEqualTo("/test-url")));
I get an exception that is similar to this:
Feign.FeignException: Premature EOF reading GET http://localhost:11390/test-url
at feign.FeignException.errorReading(FeignException.java:167)
at feign.InvocationContext.proceed(InvocationContext.java:42)
at feign.ResponseHandler.decode(ResponseHandler.java:122)
at feign.ResponseHandler.handleResponse(ResponseHandler.java:73)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:114)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:70)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:96)
...
Caused by: java.io.IOException: Premature EOF
at java.base/sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:567)
at java.base/sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:611)
at java.base/sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:705)
at java.base/java.io.FilterInputStream.read(FilterInputStream.java:119)
at java.base/sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3674)
at java.base/sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3667)
at java.base/sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3655)
at java.base/java.io.FilterInputStream.read(FilterInputStream.java:71)
at java.base/java.io.PushbackInputStream.read(PushbackInputStream.java:147)
at org.springframework.web.client.IntrospectingClientHttpResponse.hasEmptyMessageBody(IntrospectingClientHttpResponse.java:100)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:90)
at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:75)
at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:61)
at feign.optionals.OptionalDecoder.decode(OptionalDecoder.java:42)
at feign.InvocationContext.proceed(InvocationContext.java:36)
Tested this on :
- Spring Cloud Open Feign 4.0.2
- Feign Core 12.4 (bumped from spring's 12.1)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the retry and response-processing path shown in SynchronousMethodHandler, ResponseHandler, InvocationContext, and SpringDecoder, then run the WIremock MALFORMED_RESPONSE_CHUNK scenario from the issue. Compare it with CONNECTION_RESET_BY_PEER and verify that the malformed response causes a second request and a successful result, as the provided test expects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100