-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
OkHttpClient POST request fails when Request body size beyond certain limit #7248
Comments
Hmmm... not enough information to suggest any fixes here. I'm curious if your calling code is blocked waiting for the server to read? Can you isolate this into a standalone test case? |
@swankjesse thanks. Here is my test code. Possibly I can try using a fake server to create a standalone test.
|
Yeah this looks completely reasonable. Any chance you can post a thread dump when it stalls? I’m wondering if it’s stalling in OkHttp or possibly in coroutines somewhere? |
+1 to a thread dump. Also compare the working and non working case with an event listener printing all events including connections. https://square.github.io/okhttp/features/events/ |
@swankjesse attached the thread dump |
Here is the log for not-working case. |
Thread dump shows it's an issue with HTTP/2 flow control. It's blocking on this line:
Somehow OkHttp and your HTTP/2 server don't agree on flow control things, because the server has not granted OkHttp permission to send more bytes. If you do an HTTP/2 frame dump we should be able to assign blame to either OkHttp or your HTTP/2 server. https://square.github.io/okhttp/contribute/debug_logging/#http2-frame-logging |
@swankjesse attaching the frame dump You can see the timeout happing after the log with timestamp Will this help? |
As a part of investigating this issue: #7248
@saravr if you’ll forgive me for sitting on this for 2 months, I’ve got a PR out to add even more information to aid debugging. I’ve also got a hypothesis for what’s happening... A few streams (
Later the server does a connection-wide window update:
But is this window update big enough? In particular does it account for the received bytes of the canceled streams? The additional debugging in the PR should tell us. |
Relevant section from the HTTP/2 spec
|
One other gotcha – if you’re canceling a stream but not closing the ResponseBody, you will have flow control errors. Make sure you’re closing the response body. |
* Include more information in WINDOW_UPDATE frame logs As a part of investigating this issue: #7248 * Log a WINDOW_UPDATE frame even if it is malformed
@swankjesse Any chance this is fixed by #7801 or likely needs a similar writer side change? |
#7801 is the right fix. |
I am making a sequence of POST requests with each subsequent request passing the next token received the previous response in the request body of the new request. I am noticing that if POST HTTP request body size is beyond a certain limit, the request times out after certain number of requests in the sequence. Typical request body size is about 14KB. With OkHttpClient event listener I notice that (for the failing call)
is invoked but not
Instead override fun requestFailed(call: Call, ioe: IOException) is called with Socket timeout exception.
It works if make this call before each request (but looks like a hack)
Not sure if OkHTTPClient maintains some state within. Charles is showing Failure status with IO: Stream cancelled by CLIENT message.
I am using
Backend is not in my control and I cannot optimize the request body size. Apparently, a truncated-body request reaches server which doesn't response and hence the timeout. Is there a way to fix this issue. Note: If I replace OkHttp with Volley I do not see this issue.
The text was updated successfully, but these errors were encountered: