-
Notifications
You must be signed in to change notification settings - Fork 671
HttpClient retry may cause "unexpected message type: DefaultFullHttpRequest, state: 1" #1622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…n-persistent - When "Connection reset by peer" is observed mark the connection as non-persistent, do not wait for the channel close event to invalidate the connection. - Do not retry the request when the headers/body were sent. Fixes #1622
@xiazuojie Are you able to test this PR #1625 |
@violetagg, I've checked the PR. It should fix my specific scenario. |
And for that purpose you can disable the retries if this is needed. |
…n-persistent - When "Connection reset by peer" is observed mark the connection as non-persistent, do not wait for the channel close event to invalidate the connection. Fixes #1622
Yes, it can be opted out. But it probably should be an opt-in. |
We cannot change that behaviour for 0.9.x and 1.0.x. However with #1626 the retry will happen only if we didn't send anything with the first attempt. |
When using HttpClient for POST requests, connection resets by HTTP server may cause the client to lock in
unexpected message type: DefaultFullHttpRequest, state: 1
state for subsequent requests with the same server. It's caused by the retry feature of HttpClient.Expected Behavior
Subsequent HTTP requests work normally after a connection reset by the HTTP server.
Actual Behavior
Sometimes, the HttpClient is locked in
unexpected message type: DefaultFullHttpRequest, state: 1
state.Steps to Reproduce
The issue has happened in our production when the network was unstable, i.e. with lots of TCP connection resets.
return new PostHeadersNettyOutbound
HttpObjectEncoder#encode
, which will release the refCnt ofDefaultFullHttpRequest#content
hereHttpObjectEncoder#encode
again. However, the refCnt ofDefaultFullHttpRequest#content
was already released at step 4. Trying to encode again sometimes (not always. it depends on exact moment of the connection reset) causesjava.lang.IndexOutOfBoundsException
to be thrown at here, which leavesHttpObjectEncoder#state
inST_CONTENT_NON_CHUNK
state.io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
is thrown after at here.unexpected message type: DefaultFullHttpRequest, state: 1
because the instance ofHttpObjectEncoder
was locked inST_CONTENT_NON_CHUNK
state at step 7.Stack trace when the above situation happens, that is
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
and thenunexpected message type: DefaultFullHttpRequest, state: 1
.Possible Solution
Disable the retry feature of HttpClient.
With current implementation, retries of any HTTP request with a body (POST, PUT, etc) in case of connection reset are not safe. This feature should probably be removed (or at least disabled by default).
Your Environment
netty
, ...): netty 4.1.60.Finaljava -version
):java version "11" 2018-09-25uname -a
):Darwin MacBook-Pro.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64The text was updated successfully, but these errors were encountered: