What happens at the server when client closes the connection to the API by using readTimeout.Will the execution for the request will be done or it will break as soon as timeout occurs OR the execution will complete and the response stream clogged with the response that server is supposed to send to the user
Timeout is an untidy way to close the connection - when your side of a connection times out, there's good chance you won't be able to tell the other side you've timed out and are closing the connection. That is, the connection is not formally closed by coordinated action on both sides, it is just one side deciding it will consider it dead.
The way this is resolved is there are timeouts on both sides of the connection - if one side times out, the other side will timeout too, eventually.
As for what exactly happens on the server side: Since the server doesn't know the connection is dead until its own timeout expires, it will consider the connection good, and will normally process the request and attempt to write the response. There will probably be some buffering of the response, so attempting to write response may even seem to work to the server.
When and if the server attempts to write enough data to the response to fill the possible buffer, it will block, and then when timeout occurs an exception will be thrown, finally letting the server know that the connection timed out.
If the server doesn't fill the buffer with its response, the same (blocking, then exception) should happen when it tries to close the connection (but this may already happen outside your application, in the app server container code).
If by any chance you end up attempting to write the response after the timeout already occurred, you should get an exception right away.
So what exactly happens on server largely depends on your own code:
Either way, the server will eventually get to know the timeout occurred, but I'm not sure your application will always get this information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With