jonderry
jonderry

Reputation: 23633

Check whether an HttpServletRequest's connection is still open?

Using a synthetic load with both the client and the server running on localhost, I verified via tcpdump and netstat that the client is sending a FIN packet to the server, but the the connection is stuck in CLOSE_WAIT while the request remains queued on the server (I'm using Jetty with a queued thread pool). When a worker thread is available in the pool, the request is processed as usual by the servlet even though the connection has already been closed by the client.

What I want is a way to test whether the connection has already been closed to prevent the server from processing requests that have already timed out on the client side (I know I can set an http header on the client with a timestamp and check this on the server as long as the clocks are in sync, but I'd prefer to check the connection to see if it is still open as well).

Is what I'm trying to do possible, and if so, how?

Upvotes: 2

Views: 1262

Answers (1)

irreputable
irreputable

Reputation: 45443

I don't think so. FIN does not mean the connection is broken. It is perfectly valid that A sends B some data, followed by FIN; then A continues to read from B. Nothing wrong with this half-closed state.

Your better choice is to improve server throughput so that clients don't have to wait so long.

Upvotes: 2

Related Questions