-
Notifications
You must be signed in to change notification settings - Fork 26
TcpStream::connect timeout settings #98
Comments
Hey Ryan, thanks for opening this issue! In general |
Cool, thanks Yoshua. I'll take a look. |
Hey @yoshuawuyts, I've spent a bit of time looking into this, and what I'm seeing is that all of the similar methods for This doesn't actually set the underlying socket options, but I wonder if a simple example of showing how to do this with futures-timer might be better for many users. It seems to work based on some quick testing, but since you're a contributor to both libraries I'd love your advice on whether this would be a good pattern. use std::time::Duration;
use romio::TcpStream;
use futures::executor;
use futures_timer::{TryFutureExt};
executor::block_on(async {
let stream = TcpStream::connect(&HOST.parse().unwrap()).
timeout(Duration::from_millis(500))
.await;
match stream {
Ok(s) => {
println!("it worked: {:?}", s);
},
Err(ref e) if e.kind() == ErrorKind::TimedOut => {
println!("timed out");
},
Err(e) => {
println!("some other type of error: {}", e);
},
}
}); |
There's a non-zero chance that the reason it isn't in there is because nobody bothered to add it before. For example the windows I see three paths forward:
To be fair the What do you think? |
I went ahead and implemented this on the Even if it did work, this doesn't help I'm not familiar with Let me know! Best, |
As a bit of an epilogue to this issue, using a timeout via Turns out this is a really tricky problem, and the more you dig into it the more weird edge cases you find! At some point I may attempt to add a thread-local futures timer, but for now I've just moved the timeout to an optional configuration. (Feel free to close this issue; not sure what your strategy is for closing pending issues without a clear resolution like this.) |
Hi there,
I read through some of the other issues on timers in
romio
, but it seemed slightly different than changing the underlyingmio/net2
settings. I want to open a large number of TCP connections to different hosts, which may or may not respond. In order to prevent an excessive number of open files on the client I want to configure aggressive connection timeouts to prune connections that don't respond quickly.I'd be happy to try to submit a PR to add a
Builder
object or something to makeTcpStream
more configurable, but I'm not sure if there is somewhere I should be looking for an example of this. (I'm digging into the Rust async/await story, and I'm not experienced in it yet.)Here's a brief snippet that shows the code I'm using -- I appear to be hanging onto connections that fail for some time, and if there is an alternate path to fix I'd be happy to try that out instead.
Thanks!
Ryan
The text was updated successfully, but these errors were encountered: