-
Notifications
You must be signed in to change notification settings - Fork 213
Description
https://docs.rs/ureq/3.0.0-rc4/ureq/enum.Error.html#variant.Timeout says:
By default no timeouts are set, which means this error can’t happen.
But it can. E.g. in src/unversioned/transport/tcp.rs:
let maybe_stream = if let Some(when) = timeout.not_zero() {
TcpStream::connect_timeout(&addr, *when)
} else {
TcpStream::connect(addr)
}
.normalize_would_block();
let stream = match maybe_stream {
Ok(v) => v,
Err(e) if e.kind() == io::ErrorKind::TimedOut => {
return Err(Error::Timeout(timeout.reason))
}
Err(e) => return Err(e.into()),
};I.e. if the OS-dependent socket implementation returned ErrorKind::TimedOut after some environment-dependent timeout, ureq translates it to Error::Timeout(something) regardless of the configured timeouts.
In my test it returned Timeout(Global) (because timeout had reason = Global, I guess because it's the default when no timeouts are set?). That's particularly confusing because I would expect the global timeout to be a ureq-level concept, the least platform- or environment-dependent of all timeouts.
A guess at what to change (I'm not familiar with ureq, feel free to ignore):
- If the code above, if the
TcpStream::connect(addr)branch returnedErrorKind::TimedOut, report it asTimeout::Connectinstead oftimeout.reason. Do a similar change to all other code sites that handleio::Error. - Update https://docs.rs/ureq/3.0.0-rc4/ureq/enum.Error.html#variant.Timeout to say that timeouts may happen even if not explicitly configured, as the OS-es usually (always?) have some timeouts for socket operations.
- Update https://docs.rs/ureq/3.0.0-rc4/ureq/config/struct.ConfigBuilder.html#method.timeout_connect and other timeout_* to say that None means use the OS's default timeout for the corresponding operation, ideally listing the operations (e.g.
connect()syscall in case oftimeout_connect, at least on Linux?) (if not super many or super platform dependent? idk).