Skip to content

drpcmanager: cap concurrent streams with MaxStreams#74

Draft
suj-krishnan wants to merge 1 commit into
sujatha/flow-control-stream-enablefrom
sujatha/flow-control-max-streams
Draft

drpcmanager: cap concurrent streams with MaxStreams#74
suj-krishnan wants to merge 1 commit into
sujatha/flow-control-stream-enablefrom
sujatha/flow-control-max-streams

Conversation

@suj-krishnan

@suj-krishnan suj-krishnan commented Jul 1, 2026

Copy link
Copy Markdown

Caps the number of concurrent admitted streams a peer may open against this manager.

  • Options.MaxStreams (0 = unlimited). An inbound stream beyond the cap is refused in the read path with a stream-level KindError, without admitting it or tearing down the connection. The reject is a normal (non-control) frame so it respects write-buffer backpressure: over-cap refusals are unbounded (a peer can flood over-cap invokes), so bypassing the buffer via the control bit would let them append past MaximumBufferSize. A full buffer parks the reader, throttling the flooder.
  • The cap is a live gauge: a slot frees when a stream closes.
  • Applies only to peer-initiated (inbound) streams.

Merge safety: default 0 = unlimited, so a dependency bump changes nothing. Independent of flow control — a standalone gRPC-style MaxConcurrentStreams knob.

Tests: refuses-excess-inbound; slot-frees-after-close; zero-unlimited (default admits many). All under -race.

Deferred to follow-up (parked on sujatha/flow-control-setup-bounds, tracked on CRDB-65356): counting streams in setup against the cap, a control-payload-size bound, and a setup timeout. These bound half-open-stream memory that the admitted-stream cap alone does not; they're being landed separately to keep this PR to the concurrent-stream cap.

@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from 76f6b5d to d87ef7a Compare July 1, 2026 16:25
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch from 094e417 to e78b0d2 Compare July 13, 2026 07:00
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from d87ef7a to 02f81c4 Compare July 13, 2026 07:01
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch from e78b0d2 to b1e1843 Compare July 13, 2026 07:06
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from 02f81c4 to 96b1758 Compare July 13, 2026 07:06
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch from b1e1843 to 5a18815 Compare July 13, 2026 08:41
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from 96b1758 to 65d48d6 Compare July 13, 2026 08:41
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch from 5a18815 to 8f23265 Compare July 13, 2026 08:47
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from 65d48d6 to b9f1367 Compare July 13, 2026 08:47
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch from 8f23265 to 8c03c23 Compare July 13, 2026 08:55
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from b9f1367 to bfa4cbe Compare July 13, 2026 08:55
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch from 8c03c23 to 482d67b Compare July 13, 2026 08:59
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from bfa4cbe to fd0c66a Compare July 13, 2026 08:59
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-stream-enable branch 7 times, most recently from 0ffae48 to 2f31d5f Compare July 17, 2026 05:38
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch 3 times, most recently from 6c845e7 to 5b303d7 Compare July 20, 2026 09:12
Add Options.MaxStreams, a per-connection cap on how many concurrent
streams a peer may open against this manager. When the cap is reached an
inbound stream is refused in the read path -- before any per-stream state
is allocated -- with a stream-level KindError, leaving the connection up.
0 means unlimited.

This bounds the per-stream bookkeeping (goroutines, stream-table entries,
window counters) that the byte-based flow-control windows do not, giving
DoS resistance against a peer that opens many zero-byte streams. It is the
third flow-control bound alongside the per-stream and connection windows,
and is independent of the credit path.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@suj-krishnan
suj-krishnan force-pushed the sujatha/flow-control-max-streams branch from 5b303d7 to 88e78a0 Compare July 20, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant