Skip to content

Add ability to specify backlog size for TcpListener and UnixListener #94406

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

Closed
BartMassey opened this issue Feb 26, 2022 · 5 comments
Closed
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@BartMassey
Copy link
Contributor

BartMassey commented Feb 26, 2022

In socket-style network interfaces, the server side typically requests a "backlog" from the operating system. This controls how many requests the OS is willing to buffer before failing or ignoring new requests.

The backlogs used by std::net::TcpListener::bind, std::os::unix::net::UnixListener::bind and the nightly std::os::unix::net::UnixListener::bind_addr are currently hardwired to 128. This is a reasonable default, but there are situations where one might want to set a larger or smaller number. Also, that 128 default should probably be a publicly-exposed constant.

To address these issues I have posted a PR that provides the following new APIs:

  • std::net::TcpListener::DEFAULT_BACKLOG
  • std::net::TcpListener::bind_with_backlog
  • std::os::unix::net::UnixListener::DEFAULT_BACKLOG
  • std::os::unix::net::UnixListener::bind_with_backlog
  • std::os::unix::net::UnixListener::bind_addr_with_backlog
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Feb 27, 2022
…=joshtriplett

Add `with_backlog` functionality to `TcpListener` and `UnixListener`

Adds

* `std::net::TcpListener::DEFAULT_BACKLOG`
* `std::net::TcpListener::bind_with_backlog`
* `std::os::unix::net::UnixListener::DEFAULT_BACKLOG`
* `std::os::unix::net::UnixListener::bind_with_backlog`
* `std::os::unix::net::UnixListener::bind_addr_with_backlog`

Closes rust-lang#94406
@NotWearingPants
Copy link
Contributor

#55614

@BartMassey
Copy link
Contributor Author

I have talked with @joshtriplett about the stuff that blocked my last attempt at a PR, and am going to try again in the next couple of weeks. Sorry for leaving this sitting for so long.

@jyn514 jyn514 added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` labels Apr 9, 2023
@rustafariandev
Copy link

Any updates on this?

@BartMassey
Copy link
Contributor Author

I am sad to report that there is not. I really feel bad, but there it is.

The fundamental problem is that std::net::TcpListener::bind is supposed to be part of std for all platforms, including those that do not support adjusting the number of listeners, or don't have the concept of a backlog at all. The suggestion has been to ignore the backlog parameter on those platforms, as well as ignoring it when it is out of bounds for the platform. However, that seems to me to be a recipe for surprises: if I ask for a particular backlog I expect to either get that backlog or have the call fail. But… the problem with having the call fail is that I don't have access to a bunch of the weirder platforms and the conditions under which the backlog is legal are not well documented.

So I got stuck and never really got back to it.

You can take a look at the patch linked above for how far I got. I can try to have some more discussion with folks and find a student for this.

@Mark-Simulacrum
Copy link
Member

Closing as a duplicate of #55614, I don't think we need two issues for this.

@Mark-Simulacrum Mark-Simulacrum closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants