Blblblblblblbl
Blblblblblblbl

Reputation: 284

What is an idle http connection?

I am working with http connection and using a MultiThreadedHttpConnectionManager and httpClient.

For my purpose I am closing all the idle connection after 1ms with the following method : closeIdleConnections(1).

I am wondering what is considered as an " idle connection" in http ? It seems that waiting for an answer is not an idle connection.

Regards,

Upvotes: 4

Views: 19688

Answers (2)

Tony
Tony

Reputation: 1528

By studying the source code, in the HttpClient MultiThreadedHttpConnectionManager implementation, connection is simply considered idle when the connection in the pool's age is more than the idleTime. The idleTime is passed to the method closeIdleConnections(idleTime) as an argument.

Upvotes: 1

hrbrmstr
hrbrmstr

Reputation: 78822

HTTP (1.1) specifies that connections should remain open until explicitly closed, by either party. Beyond that the specification provides only one example for a policy, suggesting using a timeout value beyond which an inactive (idle) connection should be closed. A connection kept open until the next HTTP request reduces latency and TCP connection establishment overhead. However, an idle open TCP connection consumes a socket and buffer space memory.

Excerpt from RFC 7230:

6.5. Failures and Timeouts

Servers will usually have some time-out value beyond which they will no longer maintain an inactive connection. Proxy servers might make this a higher value since it is likely that the client will be making more connections through the same server. The use of persistent connections places no requirements on the length (or existence) of this time-out for either the client or the server.

When a client or server wishes to time-out it SHOULD issue a graceful close on the transport connection. Clients and servers SHOULD both constantly watch for the other side of the transport close, and respond to it as appropriate. If a client or server does not detect the other side's close promptly it could cause unnecessary resource drain on the network.

A client, server, or proxy MAY close the transport connection at any time. For example, a client might have started to send a new request at the same time that the server has decided to close the "idle" connection. From the server's point of view, the connection is being closed while it was idle, but from the client's point of view, a request is in progress.

Upvotes: 5

Related Questions