5

I am trying to call REST API from Spring MVC application using REST Template. While doing so , We have to set timeout values (connection-timeout and read-timeout) and are maintaining in YML file.

Timeouts are read from YML and are set while initializing rest template.

For E.g if I have scenario like :- connection-timeout = 5 sec , read timeout = 3 sec

My question is when read timeout will occur ?

considering worst case scenario (connection is established at 5th sec , will read timeout will occur after that meaning at 8th sec [response received at 3rd sec] ? )

Are both these timeouts are dependent on each other ?

I searched for the same however did not get answer for that as I got the information as connection timeout is for establishing the connection and read will occur while reading from connection however does read timeout value includes connection timeout value as well is not clear.

It may be basic question, however I am confused so any guidance/pointers on the same will be helpful.

Thanks !

EDIT : I have gone through the "Spring rest template readTimeOut" and it says the clock starts when the request first hits that socket and stops when whichever of these comes first: the request completes or the readTimeout is reached but I understand while establishing connection as well there will be hit to socket. Does it mean readtimeout is inclusive of connection timeout as well ?

Kedar Joshi
  • 147
  • 1
  • 1
  • 4
  • Possible duplicate of [Spring rest template readTimeOut](https://stackoverflow.com/questions/45713767/spring-rest-template-readtimeout) – Mustafa Aug 26 '18 at 14:48
  • @Mustafa Thanks Mustafa ! I have gone through the same and it says counter will start once we hit the socket. Does that mean it will be after "connection is established" ? I understand that while creating connection as well there will be hit to connection – Kedar Joshi Aug 26 '18 at 15:00
  • Yes, as far as I can tell, connection timeout applies to opening the connection and read timeout applies after the connection has been established. – Mustafa Aug 26 '18 at 15:14
  • @KedarJoshi Yes, you cannot call read() on a socket that's not yet connected. The first read() has to come after connection established. In most cases, also, the client writes first to socket before calling read(). – Antti Rytsölä Jan 10 '19 at 11:24

1 Answers1

1

They're independent of each other. Let's say httpUrlConntection.setConnectTimeout(10000); httpUrlConntection.setReadTimeout(10000);

So we have 10 seconds before TCP handshake should occur. And once read is triggered, we have 10 seconds till the packets are read. If the response is not fully transferred, an exception is thrown.

For conceptual understanding : What is the difference between connection and read timeout for sockets?