-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Fix windows Socket::connect_timeout overflow
#112464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
22f62df
fca9e6e
f65b5d0
30e1c1a
a0c757a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,37 @@ fn connect_error() { | |
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn connect_timeout_to_unreachable_address() { | ||
| let now = Instant::now(); | ||
| match TcpStream::connect_timeout(&format!("1.1.1.1:9999").parse().unwrap(), Duration::MAX) { | ||
| Ok(..) => panic!("connected to an unreachable address, this is impossible"), | ||
| Err(e) => assert_eq!(e.kind(), ErrorKind::TimedOut), | ||
| } | ||
|
|
||
| assert!(now.elapsed() > Duration::from_secs(20)); | ||
| } | ||
|
|
||
| #[test] | ||
|
eval-exec marked this conversation as resolved.
Outdated
|
||
| fn connect_timeout_error() { | ||
| let socket_addr = next_test_ip4(); | ||
| let result = TcpStream::connect_timeout(&socket_addr, Duration::MAX); | ||
| assert!(!matches!(result, Err(e) if e.kind() == ErrorKind::TimedOut)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a strange test. It says to only timeout after billions of years, yet apparently it expects the OS to timeout immediately. What is going on here? And why is there no comment explaining this?^^ Context: #156385
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I missed a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, I reviewed your PR. Is there some tasks we can do next for further steps?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the comment there makes sense then I think that's all, thanks :) |
||
|
|
||
| let _listener = TcpListener::bind(&socket_addr).unwrap(); | ||
| assert!(TcpStream::connect_timeout(&socket_addr, Duration::MAX).is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn connect_timeout_ok_bind() { | ||
| let listener = TcpListener::bind("127.0.0.1:0").unwrap(); // :0 picks some free port | ||
| let port = listener.local_addr().unwrap().port(); // obtain the port it picked | ||
| assert!( | ||
| TcpStream::connect_timeout(&format!("127.0.0.1:{port}").parse().unwrap(), Duration::MAX) | ||
| .is_ok() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn listen_localhost() { | ||
| let socket_addr = next_test_ip4(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested, this unit test will cost at 2 minutes and 8 seconds on Linux platform, and cost 20 seconds on Windows.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only need one test here. We only need to focus on testing the problematic code path in one way. 2 minutes and 8 secs is a long time for a single unit test so I'd prefer if we just used
connect_timeout_errortest and removed the other two.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think 2 minutes and 8 seconds is a long time too.