JavaDeveloper
JavaDeveloper

Reputation: 5660

Will client timeout if a request on HTTP persistent connection takes a long time?

If we have a HTTP persistent connection, however one of the request takes a long time (say 30 seconds). Assume client's timeout is 15 seconds.

  1. Is client's reques-timeout respected when used over persistent connection ?

  2. If yes, then does the connection break ?

  3. Is there any way to avoid the entire connection from breaking, and instead just timing out on that one particular request ?

Upvotes: 2

Views: 1324

Answers (2)

Flash Thunder
Flash Thunder

Reputation: 12045

That depends of what client you are using and how the server is configured. The problem is more complicated... setting keep-alive in http won't avoid tcp timeouts at transport level, you need to set tcp timeout to keep-alive as well, but then server may not want to keep a connection for you as long as you would like to. For persistent connections it is better to use udp instead of tcp - it doesn't have such a strict flow control. Other thing is that HTTP/2 has no such a thing as keep-alive at all, as things are handled in totally different way than in HTTP/1. From the HTTP/2 RFC:

8.1.2.2. Connection-Specific Header Fields

HTTP/2 does not use the Connection header field to indicate
connection-specific header fields; in this protocol, connection-
specific metadata is conveyed by other means. An endpoint MUST NOT
generate an HTTP/2 message containing connection-specific header
fields; any message containing connection-specific header fields MUST be treated as malformed (Section 8.1.2.6).

The only exception to this is the TE header field, which MAY be
present in an HTTP/2 request; when it is, it MUST NOT contain any
value other than "trailers".

This means that an intermediary transforming an HTTP/1.x message to HTTP/2 will need to remove any header fields nominated by the
Connection header field, along with the Connection header field
itself. Such intermediaries SHOULD also remove other connection-
specific header fields, such as Keep-Alive, Proxy-Connection,
Transfer-Encoding, and Upgrade, even if they are not nominated by the Connection header field.

Upvotes: 0

Afshin
Afshin

Reputation: 1509

  1. Client can specify timeout but it depends on the server configuration for using client timeout or its own timeout configuration. By default server side timeout configuration has more priority than client timeout configuration.
  2. No
  3. For having one particular request with different timeout config it's not possible on the same connection But, you can declare different http client config connection and use one of them for default and another one for request that need much more timeout value But they are not in the same keep-alive connection.
    Note, In the client side timeout configuration we have two different type of timeout
    1- Open Connection Timeout 2- Read Response Timeout.
    The first one is declared for open connection between server and client and the second one is declared for how much time client needs to get response for his request.

Upvotes: 1

Related Questions