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

Fix an inconsistency in Linux version of TcpListener::accept #67028

Closed
wants to merge 1 commit into from

Conversation

hashmap
Copy link

@hashmap hashmap commented Dec 4, 2019

If TcpListener is in non-blocking mode then accepted streams inherit
this property on all platforms except Linux, where accept4 is used
instead of accept.

This fix checks if a listener is in non-blocking mode and pass the
corresponding flag to accept4.

Fixes #67027

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Kimundi (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 4, 2019
@hashmap hashmap changed the title Fix an inconsitency in Linux version of TcpListener::accept Fix an inconsistency in Linux version of TcpListener::accept Dec 4, 2019
@sfackler
Copy link
Member

sfackler commented Dec 4, 2019

That implementation is racy with concurrent changes to the blocking-ness of the socket. It also doubles the number of system calls per accept call.

We generally try to expose the system primitive without a lot of extra stuff on top. "TcpListener::accept calls accept4(2)" is a lot simpler than "TcpListener::accept calls accept4(2) and then tries to patch other bits of the socket up". CLOEXEC is the ~one exception to this rule since it's so important.

@hashmap
Copy link
Author

hashmap commented Dec 4, 2019

Agree reg race, I found unfortunate that set_nonblocking and friends don’t take a mutable reference, while it doesn’t mutate any state in rust code it does system wide.

It also doesn’t allow to introduce any state to avoid extra syscall, however that design may be error prone. I think for non-blocking io in the majority of the cases we would have the same amount of syscalls, while doubling it for blocking io.

I’m not sure about the last point. I think about complexity from api user point of view. How many people needs to know details of impl and how hard to figure it out? At the same time there are millions of users of this method and for them we have a complex story - “what you get depends on listener state unless you are on linux then you always get blocking stream”. Also there is no single hint that this call is platform-dependent.

@Dylan-DPC-zz
Copy link

r? @KodrAus

@rust-highfive rust-highfive assigned KodrAus and unassigned Kimundi Dec 11, 2019
@bors
Copy link
Contributor

bors commented Dec 20, 2019

☔ The latest upstream changes (presumably #67449) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 18, 2020
@JohnCSimon
Copy link
Member

Ping from triage: @hashmap can you please address the merge conflicts?

@JohnCSimon
Copy link
Member

Pinging again from triage: @hashmap can you post the status of this pr? Thanks.

If TcpListener is in non-blocking mode then accepted streams inherit
this property on all platforms except Linux, where accept4 is used
instead of accept.

This fix checks if a listener is in non-blocking mode and pass the
corresponding flag to accept4.

Fixes rust-lang#67027
@hashmap
Copy link
Author

hashmap commented Jan 28, 2020

Sorry, I've finally rebased this pr.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-28T17:03:32.6223666Z ========================== Starting Command Output ===========================
2020-01-28T17:03:32.6226175Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/b6fd0137-099f-4535-9c77-56bff62c9f91.sh
2020-01-28T17:03:32.6226215Z 
2020-01-28T17:03:32.6229001Z ##[section]Finishing: Disable git automatic line ending conversion
2020-01-28T17:03:32.6234209Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67028/merge to s
2020-01-28T17:03:32.6235792Z Task         : Get sources
2020-01-28T17:03:32.6235826Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-28T17:03:32.6235897Z Version      : 1.0.0
2020-01-28T17:03:32.6235931Z Author       : Microsoft
---
2020-01-28T17:03:33.6917398Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-28T17:03:33.6929172Z ##[command]git config gc.auto 0
2020-01-28T17:03:33.6932358Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-28T17:03:33.6934298Z ##[command]git config --get-all http.proxy
2020-01-28T17:03:33.6940951Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67028/merge:refs/remotes/pull/67028/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@sfackler sfackler added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 28, 2020
@sfackler
Copy link
Member

I'm still not convinced that the standard library should be trying to fudge this.

@rfcbot fcp close

@rfcbot
Copy link

rfcbot commented Jan 28, 2020

Team member @sfackler has proposed to close this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-close This PR / issue is in PFCP or FCP with a disposition to close it. labels Jan 28, 2020
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Feb 7, 2020
@rfcbot
Copy link

rfcbot commented Feb 7, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@RalfJung
Copy link
Member

Also there is no single hint that this call is platform-dependent.

Adding documentation to explain this better would probably makes sense, if the decision is to not change behavior.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Feb 17, 2020
@rfcbot
Copy link

rfcbot commented Feb 17, 2020

The final comment period, with a disposition to close, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@sfackler sfackler closed this Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-close This PR / issue is in PFCP or FCP with a disposition to close it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linux version of nonblocking TcpListener::accept differs from other platforms
10 participants