http_req icon indicating copy to clipboard operation
http_req copied to clipboard

copy_with_timeout() may exceed its timeout

Open Shnatsel opened this issue 4 years ago • 0 comments

copy_with_timeout() as implemented in v0.7.2 may exceed its deadline:

https://github.com/jayjamesjay/http_req/blob/eba0471369662667c27c0a46541b8cb464c8edc0/src/request.rs#L50-L75

In here the timeout is only checked after the read operation is issued. However, a call to read() may block according to the documentation. If used on a reader that reads from a network socket, IIRC it will block waiting for data from the remote server until the underlying TCP timeout expires (5 minutes by default).

I believe this is a fundamental limitation of the approach; I am not aware of any ways to fix it without spawning an auxiliary thread or using an async runtime.

If a read timeout is desired, it should be configured on the socket explicitly instead.

If a timeout for the entire request is desired, it can be implemented either by spawning an auxiliary thread that interrupts the main thread (as done in attohttpc), or by setting the read timeout to the minimum of read timeout and the remaining time until the deadline for the entire request (as done in minreq).

Shnatsel avatar Feb 12 '21 18:02 Shnatsel