-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Apache HTTP Client often hangs forever (deadlocks) in async block #770
Comments
Here's a thread dump of the deadlock situation with After this point, the JVM is completely idle, the JVisualVM reports no cpu activity on any thread whatsoever. |
I've run into a similar issue I believe while using the Apache engine as well. In my case I'm using the Gson serializer and I've noticed that when it freezes it hangs up within |
Hi @MartinHaeusler, thanks for the report. |
@e5l Thanks for the heads-up. I just ran the JUnit test again with KTOR |
Thanks for the report, I'll investigate and report the details. |
It looks like we hanging in the |
Fixed in |
Forgive me for being curious, but was the issue in the Apache HTTP client itself, or in the KTOR client wrapper? |
The issue was in So single |
Oh okay... well, I'm glad to see this issue fixed, thanks for the explanation 😃 👍 |
Ktor Version
1.0.0
Ktor Engine Used(client or server and name)
Apache HTTP Client
JVM Version, Operating System and Relevant Context
Oracle JDK 1.8.0_161-b12 (same issue on OpenJDK 8)
OS: Windows 10, 64bit
Feedback
When running the Apache HTTP client (through the ktor client API), the client sometimes just "freezes" and hangs indefinitly, sending the application into a deadlock. This effect is very noticeable when calling the client from an
async
block.Please consider the following self-contained JUnit test:
In particular,
testWithGlobalScope
(Apache HTTP, called fromGlobalScope.async(...)
) tends to freeze almost every try at some point (although I observed that the target web URL does make a difference; perhaps it's a race condition dependent on the response time?). The other two variants work fine for me.As a side note, I have observed that if you are in a test run where the HTTP client causes a freeze, it will always occur after the
n
-th request, wheren
is the number of CPU cores on your machine (I guess that kotlin determines the size of its executor pools based on this number, when the pools run out of usable threads the remaining coroutines can't execute anymore).Interestingly, if we replace
HttpClient(Apache)
byHttpClient(CIO)
, then things work like a charm. I would argue that this strongly points towards the Apache HTTP Client as the culprit of the deadlocks.The text was updated successfully, but these errors were encountered: