Skip to content
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

Strengthen/clarify "It is an error to..." wording #48311

Closed
frewsxcv opened this issue Feb 18, 2018 · 6 comments
Closed

Strengthen/clarify "It is an error to..." wording #48311

frewsxcv opened this issue Feb 18, 2018 · 6 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@frewsxcv
Copy link
Member

For all of the APIs above, the docs have a line with this wording:

It is an error to pass the zero Duration to this method.

My initial thought is, what does "it is an error" mean? Does this mean the API will panic if Some(Duration::from_secs(0)) is passed or will it just return an Err? The answer appears to be the latter.

Also since it's the latter, and we don't have an explicit check for Duration(0) in our codebase, it means we're relying on the behavior being the same across all platforms. Is this alright? Should/can we add an explicit check for Duration(0)? Should we add a test ensuring this is the behavior across all platforms?

Maybe I'm overthinking this...

@frewsxcv frewsxcv added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Feb 18, 2018
@sfackler
Copy link
Member

We do have an explicit check:

if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot set a 0 duration timeout"));
}

if timeout == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot set a 0 duration timeout"));
}

@frewsxcv
Copy link
Member Author

frewsxcv commented Feb 18, 2018

@sfackler ah, i didn't see those. i just checked redox and it looks like it doesn't have that conditional. seems like this is prone to happen again in the future, unless we had:

  • an integration test suite for std::net things such that we could assert that an Err is returned in this scenario
  • or, the conditionals were moved into the body of the top-level entry point of these APIs instead of the platform specific ones

@sfackler
Copy link
Member

Yeah it seems reasonable to have tests to check for that error case.

@frewsxcv
Copy link
Member Author

@sfackler for TcpStream::set_read_timeout for example, do you know if we have a way to test this method in our test suite? seems like it would require TcpStream::connect to be called, which seems like it would require a TCP listener running

@sfackler
Copy link
Member

sfackler commented Feb 18, 2018

I'd just spawn off a listener in a background thread:

let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();

thread::spawn(move || {
    listener.accept().unwrap();
});

let socket = TcpStream::connect(addr).unwrap();
match socket.set_read_timeout(Some(Duration::from_secs(0))) {
    Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {}
    _ => panic!("expected error"),
}

@frewsxcv frewsxcv changed the title Strengthen/clarifying "It is an error to..." wording Strengthen/clarify "It is an error to..." wording Feb 18, 2018
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 19, 2018
@TimNN TimNN added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Feb 20, 2018
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 24, 2018
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 25, 2018
…on, r=sfackler

Add tests ensuring zero-Duration timeouts result in errors; fix Redox issues.

Part of rust-lang#48311
kennytm added a commit to kennytm/rust that referenced this issue Feb 25, 2018
…on, r=sfackler

Add tests ensuring zero-Duration timeouts result in errors; fix Redox issues.

Part of rust-lang#48311
@frewsxcv
Copy link
Member Author

frewsxcv commented Mar 3, 2018

This is done, as of #48328 and #48330

@frewsxcv frewsxcv closed this as completed Mar 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants