Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Threads stuck when jersey client with apache connector is used concurrently #3772
Using jersey client with apache connector from multiple threads concurrently results in threads that wait forever
How to reproduce
Run the following code
With this maven pom.xml
"All done" is written in the console and (optionally, see notes below) the program finishes
One of the threads gets stuck with the following thread dump output
Happens here also, and we don't use docker, just TestNG.
We use TestNG to test our SDK which have multiple places it calls Jersey 2.x to perform various server access tasks. Once we added a new feature (which communicates with the server using
We narrowed it down to one of the new
This is the stacktrace:
As I'm looking at this issue, it seems the problem lies beneath Jersey framework. Trying to reproduce the issue I tried described steps and it really hangs. However it hangs on waiting results of the completable feature. As per specification the get() method of the completable feature waits until the feature is completed. And it shall be completed as soon as the response is received. However response never comes. What says thread dump is that thread is waiting on SessionInputBufferImpl.streamRead (and some steps below). Which is correct. But response never comes. so feature never gets completed thus it looks like everything is hanged. Jersey layer is just a mediator here so it does not cause hanging it just waits for the feature completion as well.
well yes, I can confirm that. The issue happens since Jersey 2.22.2. Further more I've localized the reason why it happens and will try to fix that. The issue is caused by wrapping of the response input stream together with response instance itself in attempt to close both stream and response (which does not seam to be a good idea). This causes hanging.