Blocking Tomcat thread to connect to localhost

I have a head cleaner who was worried after a few days.

I have a couple of webapps deployed under tomcat (7/8 doesn't matter, the problem remains) and their interaction is giving me a headache.

Flow:

Let's say I have app A and app B deployed in the same cat. Application A accepts an external HTTP request R1, does something, and sends another HTTP request to Application B on the same cat. After sending the request, the R1 thread is put into a wait state by the Java Object.wait () method.

Application B receives the R2 request sent by Application A, processes it, and sends the request to Application A.

Application A accepts R3's request, does some processing, and again makes R4's request to Application B (this is a kind of notification) and wakes up the processing of R1 threads that is waiting at that point.

X  Req1    A         B
|--------->|  Req2   |
|          |-------->|
|          |  Resp2  |
|          |<........|
|          |  Req3   |
|          |<--------|
|          |  Resp3  |
|          |........>|
|          |  Req4   |
|          |-------->|
|          |  Resp4  |
|  Resp1   |<........|
|<.........|         |

      

Problem:

Everything is going great except for the R4 notification request. This request hangs from time to time. Processing gets stuck when an HTTP connection is waiting for a response code. After the request expires, after 30 seconds, Application B logs the request it received and returns fine. This happens immediately after the request has timed out.

The dangling occurs only if this R4 request is made to application B located in the same cat. If app B is running on some other server, the call runs 100% of the time. This is also just one place where the challenge fails. This is not an actual call issue as I could change the notification call to make any other call at the same location and it would randomly hang up.

Can someone shed some light on this issue and point me in the right direction. I'm running out of ideas.

+3


source to share


1 answer


Writing a problem here gave me some new ideas and I started to expand my scope.

I tried the deal with Jetty as well, and after giving the same hang I was pretty sure it was in my code somehow.

It turned out that before sending R4 to app B, app A writes to HttpServletResponse R3.



response.getWriter().println(responseContent);
response.getWriter().flush();
response.getWriter().close();

      

Here, the closure of the stream was what caused everything to break down. I removed the close () call and now the R4 request works as it should.

I have no idea why closing the response stream will cause the next new HTTP request to be seen as if it ...

0


source







All Articles