-
Notifications
You must be signed in to change notification settings - Fork 985
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
Should StreamMuxerBox
track how many "active" substreams are still around?
#2865
Comments
Tagging as "help wanted" because I'd like to get people's input on this idea. |
StreamMuxerBox
track how many "active" substreams are still aroundStreamMuxerBox
track how many "active" substreams are still around?
I like the idea. Though instead of using the I am against using |
The issue I see with that is that we don't know, when a stream is de-allocated unless we use some kind of shared, atomic counter that is decremented on |
I think my comment was misleading @thomaseizinger. Let me rephrase:
I am against using Sorry. Is the second attempt more clear? |
Sort of. I wouldn't know how to enforce a limit via What I am proposing in this issue is to use expose functions on impl StreamMuxerBox {
pub fn active_inbound_streams(&self) -> usize;
pub fn active_outbound_streams(&self) -> usize;
} The implementation will return The motivation for this issue was to use it in |
Draft implementation here: #2878 I noticed that we are unnecessarily exposing the |
Description
Whilst thinking about #2863, I noticed that it is very easy to (accidentally) circumvent the limit on inbound substreams by "leaking" them to the
ConnectionHandler
. We do this in various places withinrust-libp2p
and I am sure it happens in within code-bases of ours users too.StreamMuxerBox
already boxes up each substream as aSubstreamBox
. We could extendSubstreamBox
with aWeak<()>
whereStreamMuxerBox
owns the correspondingArc<>
. This would makeArc::weak_count
effectively be the count of all active (i.e. not dropped) substreams the muxer has given out.Within
Connection
, we know aboutStreamMuxerBox
so we could expose functions on it to give us the current count of active inbound and outbound streams, which would allow us to actually enforce a limit on those.Motivation
Not limiting the number of inbound streams can cause unexpected memory and CPU growth and in the worst case, is exploitable via a DoS attack.
Downsides
Rolling out this change may negatively affect users because they will suddenly experience a limit where there wasn't one before.
Current Implementation
Are you planning to do it yourself in a pull request?
Yes.
The text was updated successfully, but these errors were encountered: