Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read and Write timeouts behavior

Tags:

okhttp

What is the behavior of read and write timeouts in OkHttp?

Is the timeout exception triggered when the whole request exceeds the timeout duration or is when the socket doesn't receive (read) or send (write) any packet for this duration.

I think is the second behavior but could someone clarify this?

Thanks in advance.

like image 751
Alex Miragall Avatar asked Aug 28 '15 09:08

Alex Miragall


1 Answers

The timeouts are triggered when you block for too long. On read that occurs if the server doesn't send you response data. On write it occurs if the server doesn't read the request you sent. Or if the network makes it seem like that's what's happening!

Timeouts are continuous: if the timeout is 3 seconds and the response is 5 bytes, an extreme case might succeed in 15 seconds just as long as the server sends something every 3 seconds. In other words, the timeout is reset after ever successful I/O.

Okio’s Timeout class also offers a deadline abstraction that is concerned with the total time spent.

like image 137
Jesse Wilson Avatar answered Sep 23 '22 00:09

Jesse Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!