Question

I am encountering an interesting issue wherein a TCP connection for a HTTP 1.1 POST request is being closed immediately following the request (ie, before the response can be sent by the server).

A few details about the test environment:

Client - Windows XP, Internet Explorer 8, Flash player 12.

Server - Java 7

Prior to the aforementioned behaviour, we have several longstanding TCP connections, each being reused for multiple HTTP requests; we open a long poll and when this poll completes, open another. We see several hours of well behaved and reused TCP connections opening polls as the previous poll closes. Eventually -- sometimes after 12 or more hours of normal behaviour -- a poll on a long standing connection will send the HTTP POST and immediately send a TCP FIN before the server can write the response.

The client behaviour is to keep a poll open at all times, so at this point we try to open a new poll.

A new TCP connection is then opened by the client sending another HTTP POST, with the same behaviour; the request is sent, followed by a FIN from the client.

This behaviour can continue for several minutes, until the server can finally respond to kill the client. (The server detects the initial closed connection by encountering an IO Exception, the next time it can communicate with the client, the response is to tell the client to close)

Edit: We are opening connections only through the Flash client, and are not delving into low level TCP code. While Steffen Ullrich is correct, and the single sided shutdown is possible and should be dealt with, what is not clear is why a single sided shutdown is occurring at this (seemingly arbitrary) point. We are not calling close from the application to instigate this behaviour.

My questions are:

  1. Under what circumstances would a TCP connection for a HTTP request be terminated prior to the response being received? I understand this is bad behaviour, and an incomplete HTTP transaction, so presumably something lower down is terminating the connection for an unknown reason.

  2. Are there any diagnostics that could be used to help understand the problem? (We are currently monitoring server and client side activity with Wireshark.)

Notes:

In Wireshark, the behaviour we see is:

  1. Longstanding TCP connection (#1) serving multiple HTTP requests.
  2. HTTP request is made over #1.
  3. Server ACKs the request.
  4. Client sends FIN to close connection #1. Server responds with FIN,ACK. (The expected traffic would be the server sending the HTTP response). Around this point the server experiences an IO Exception.
  5. Client opens connection #2 and sends HTTP request.
  6. Behaviour continues as from 3.

No correct solution

OTHER TIPS

Sending a request immediatly followed by a FIN is not a connection close, but shutdown of writing shutdown(socket,SHUT_WR). The client tells the server this way that it will not send any more data, but it might still receive data. It's not that uncommon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top