Add Server::max_concurrent_connections(usize)
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
Add `tonic::transport::Server::max_concurrent_connections(limit: usize)` which limits the number of concurrent connections that are allowed to be served at the same time. If we reach this limit, then the server will wait until a connection drops before calling `.accept()` on the socket again.
The change would require guarding the `listener.accept()` call with a semaphore [here](https://github.com/hyperium/tonic/blob/87f195b5fd24efe96e5f8010fada0c3e75225976/tonic/src/transport/server/mod.rs#L612) and passing the permit of that semaphore to `serve_connection` [here](https://github.com/hyperium/tonic/blob/87f195b5fd24efe96e5f8010fada0c3e75225976/tonic/src/transport/server/mod.rs#L638).
I'm happy to make a PR if the contribution is welcome
Contributor guide
Assessment
This issue has not been assessed yet.