Bound bi-stream handler concurrency at accept site#477
Open
MorganaFuture wants to merge 2 commits into
Open
Conversation
A peer could open unbounded bi-streams and exhaust memory before the inner `agent.limits().sync` check inside `serve_sync` ever fired. Move the try_acquire up to `spawn_bipayload_handler`, before `tokio::spawn`, and write `MaxConcurrencyReached` on the stream when no permits remain. The duplicate check inside `serve_sync` is removed: keeping both would consume two permits per sync from the same 3-permit pool.
somtochiama
reviewed
May 13, 2026
| // adding a parallel counter. Acquiring before `tokio::spawn` | ||
| // prevents an unbounded peer from exhausting tasks/memory just | ||
| // by opening streams. | ||
| let permit = match agent.limits().sync.clone().try_acquire_owned() { |
Contributor
There was a problem hiding this comment.
Maybe we'd want to make this configurable? Right now we have it set to three and there's no way to tune it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A peer could open unbounded bi-streams and exhaust memory before the inner
agent.limits().synccheck insideserve_syncever fired. Move the try_acquire up tospawn_bipayload_handler, beforetokio::spawn, and writeMaxConcurrencyReachedon the stream when no permits remain.The duplicate check inside
serve_syncis removed: keeping both would consume two permits per sync from the same 3-permit pool.