-
Notifications
You must be signed in to change notification settings - Fork 974
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
swarm/: Limit negotiating inbound substreams per connection #2697
swarm/: Limit negotiating inbound substreams per connection #2697
Conversation
This limit is shared across all `ConnectionHandler`s on a single connection. It only enforces a limit on the number of negotiating substreams. Once negotiated a `ConnectionHandler` manages the lifecycle of the substream and has to enforce limits themselves.
@@ -243,6 +247,11 @@ where | |||
) { | |||
match endpoint { | |||
SubstreamEndpoint::Listener => { | |||
if self.negotiating_in.len() == MAX_NUM_NEGOTIATING_IN { |
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.
Instead of doing this check here, we could create a wrapper around FuturesUnordered
that enforces a limit on the number of concurrent futures. This would foster reuse and actually enforce this limit. At the moment, there is a risk that this check is circumvented in case the FuturesUnordered
is modified in a different place without this check.
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.
👍 for the reusable abstraction, though I would much rather like to remove the entire upgrade mechanism for substreams in the future.
@@ -35,6 +35,10 @@ use libp2p_core::{ | |||
}; | |||
use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration}; | |||
|
|||
/// The maximum number of incoming streams concurrently negotiated. Streams are | |||
/// dropped and thus reset. | |||
const MAX_NUM_NEGOTIATING_IN: usize = 128; |
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.
How was this number chosen?
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.
Lgtm!
Description
This limit is shared across all
ConnectionHandler
s on a single connection. Itonly enforces a limit on the number of negotiating substreams. Once negotiated a
ConnectionHandler
manages the lifecycle of the substream and has to enforcelimits themselves.
Links to any relevant issues
Open Questions
Change checklist