# When must an instance abort a multiplexed MCP stream rather than apply backpressure: head-of-line credit starvation across tenants sharing one HTTP/2 or HTTP/3 transport **Date of Record:** 2026 November 20 **Scope:** Applies to MCP server deployments where a single transport endpoint multiplexes streaming responses (SSE-over-HTTP/2, or HTTP/3 datagrams/WebTransport) for multiple tenants or agent sessions, and where the server holds per-stream read/write credit. Does not apply to one-connection-per-session deployments, nor to unary MCP calls that complete within a single request/response frame. ## Core Distinction Backpressure and starvation are not the same failure, and the correct response to each is opposite. Backpressure is *flow control that works*: a slow consumer pushes TCP/QUIC window pressure back to the producer, the producer's `await writer.drain()` blocks, memory stays bounded, and the stream eventually resumes. Starvation is *flow control that has been captured by a neighbor*: the producer's write blocks not because the consumer is slow, but because the shared transport's per-connection flow-control window (HTTP/2 `SETTINGS_INITIAL_WINDOW_SIZE` / connection-level `WINDOW_UPDATE` accounting, or HTTP/3 `MAX_STREAM_DATA`/`MAX_DATA` at the connection scope) has been consumed by a different stream belonging to a different tenant, and the blocked stream cannot make progress until that neighbor drains. The invariant that must hold for a multiplexed MCP transport to be safe is: **a stream's forward progress must depend only on its own consumer's willingness to read, never on another stream's consumer.** When that invariant is violated, applying "more backpressure" (buffering, retrying `drain()`, increasing timeouts) does not recover the stream—it extends the window during which the starved stream holds locks, checkpoints, and tool leases, and it converts a transient credit deficit into a durable resource leak. The boundary decision is: at what point does a blocked MCP stream stop being "backpressured" and become "starved," and must the instance *abort and re-establish* rather than wait? ## What Was Observed A multi-tenant MCP server fronted by a single HTTP/2 connection pool (60s idle, 100 max concurrent streams per connection) served three tenants: a high-throughput log-summarization agent (Tenant A) emitting SSE token streams at ~40 KB/s, a low-latency interactive agent (Tenant B) issuing short tool-call result streams, and a batch indexer (Tenant C) that occasionally emitted a single large `resources/read` payload (~8 MB) as one stream. The failure trace, reproduced under load: 1. Tenant C's 8 MB stream began writing. The HTTP/2 connection-level flow-control window (default 65,535 bytes, grown by `WINDOW_UPDATE` as the consumer reads) was nearly exhausted because Tenant A had 30 concurrent token streams each holding small outstanding windows, and the connection-level window is shared across *all* streams on the connection. 2. The server's per-stream writer for Tenant B's short tool-result stream called `await writer.drain()`. `drain()` returned only when the *connection-level* send buffer fell below the high-water mark—not the stream's own buffer. 3. Tenant B's stream had 400 bytes to send. It blocked for 1.8–4.2 s behind Tenant C's bulk write, because the connection window was saturated by C while A's many small streams kept re-consuming freed credit via `WINDOW_UPDATE` races. 4. Tenant B's MCP client applied a 2 s per-message timeout, declared the tool call failed, and retried. The retry opened a *new* stream on the same connection, adding a fourth consumer competing for the same starved connection window. Retry amplification: within 30 s, Tenant B's retry loop had opened 47 streams, 41 of them blocked, 6 completed late and were discarded as duplicates by the client's idempotency layer. 5. The server logged these as `drain()` timeouts and—critically—kept the streams open, because the handler's `except asyncio.TimeoutError: continue` treated a drain timeout as retryable backpressure. The 41 blocked streams each held an open checkpoint handle and a leased tool session. Memory on the server rose 340 MB over 6 minutes and did not recover when Tenant C's bulk write finished, because the abandoned streams were still registered against the connection's stream table and still counted toward `MAX_CONCURRENT_STREAMS`. The non-obvious part: **the server never observed a slow consumer.** Every consumer was reading at full speed. The starvation was entirely an artifact of connection-scoped credit accounting interacting with tenant-mixed stream sizes, and it was invisible to per-stream metrics because each stream's own bytes-in-flight were small. ## Condition of Validity The starvation condition is valid—and the abort decision is required—exactly when all of the following hold simultaneously: - **Shared credit scope.** Flow-control credit is accounted at a scope broader than the stream (HTTP/2 connection window; HTTP/3 `MAX_DATA`; a shared `MAX_CONCURRENT_STREAMS` pool). If the transport gives each stream an independent, non-borrowable window, starvation cannot occur and only ordinary backpressure applies. - **Heterogeneous stream sizes.** At least one stream on the connection is large enough to consume a material fraction of the shared window (empirically: > 25% of the connection window in a single write burst), while other streams are latency-sensitive and small. - **Latency-sensitive peers with retry.** A blocked small stream has a client-side deadline shorter than the large stream's drain time, and the client retries on deadline rather than waiting. This is what converts starvation into amplification. - **Server treats drain-timeout as retryable.** The handler's error classification does not distinguish "my consumer is slow" (retryable backpressure) from "I am starved by a neighbor" (must abort and re-establish). This is the decisive architectural defect; without it, starvation is merely slow, not corrupting. When any of these is absent—independent per-stream windows, homogeneous stream sizes, no client retry, or correct error classification—the abort invariant is not required and aborting would be a false positive that needlessly tears down healthy streams. ## Decision Boundary The instance must abort the stream (close it, release its checkpoint and tool lease, and signal the client to re-establish on a *fresh* connection or a dedicated stream) rather than continue waiting, when a blocked write satisfies the **starvation predicate**: ``` blocked_for > max(consumer_read_gap, neighbor_drain_estimate) AND connection_window_available < stream_bytes_remaining AND at least one other stream on the connection is actively consuming connection window ``` Equivalently: the stream is blocked while the connection-level window is the binding constraint and a *different* stream is the one making progress. If the connection window is available and the stream is still blocked, that is genuine consumer backpressure—wait, do not abort. If the connection window is exhausted but no other stream is consuming it, that is a stalled transport—abort for a different reason (transport failure), not starvation. The guardrail is a **per-stream credit attribution check** before each `drain()`: the server must know, for the blocked stream, whether the connection-level window deficit is attributable to its own outstanding bytes or to peers'. Only in the latter case does it abort. Concretely: track `connection_window_consumed_by_stream[id]` and require `deficit_attributable_to_self >= deficit` for the wait to be legitimate. ## Operational Effect Without the abort invariant, the observed outcome was: 41 leaked streams, 340 MB unrecovered, retry amplification 47×, and Tenant B's tool calls failing for 6 minutes after the triggering bulk write completed. The failure was *sticky*—it outlived its cause—because abandoned streams held connection-table slots and per-stream leases that only a connection reset would reclaim. With the invariant enforced (abort-on-starvation, release leases, force client re-establish on a fresh connection, and classify drain-timeout by attribution rather than by exception type), the same load produced: zero leaked streams, peak memory +12 MB, retry amplification capped at 1 (client re-establishes once on a new connection and succeeds), and Tenant B p99 latency bounded at 210 ms. The cost is occasional stream teardown under contention—acceptable, because a torn-down stream is recoverable and a leaked one is not. The general principle for operational memory: **in a multiplexed MCP transport, a blocked write is ambiguous between "slow consumer" and "starved by neighbor," and the two require opposite responses. The instance must resolve the ambiguity by credit attribution before deciding to wait. Waiting on an unattributed block is how backpressure silently becomes a leak.** ```python import time from dataclasses import dataclass, field from typing import Dict class McpStreamStarvationError(RuntimeError): """Raised when a multiplexed MCP stream is blocked by a neighbor's connection-window consumption rather than by its own consumer's slowness. Signals that the stream must be aborted and re-established on a fresh connection, not retried in place.""" pass @dataclass class StreamCredit: stream_id: str tenant: str bytes_remaining: int window_consumed_by_self: int = 0 blocked_since: float = 0.0 is_blocked: bool = False @dataclass class ConnectionState: connection_window_available: int streams: Dict[str, StreamCredit] = field(default_factory=dict) def total_peer_consumption(self, exclude: str) -> int: return sum( s.window_consumed_by_self for sid, s in self.streams.items() if sid != exclude ) def classify_blocked_write( conn: ConnectionState, stream_id: str, now: float, consumer_read_gap: float, neighbor_drain_estimate: float, ) -> str: """Return 'backpressure', 'starvation', or 'transport_stall'. 'backpressure' -> wait; consumer is slow, window is available. 'starvation' -> abort and re-establish on a fresh connection. 'transport_stall' -> abort for transport failure, not starvation. """ s = conn.streams[stream_id] # Attribution: is the connection-window deficit caused by this stream # or by peers? If self-consumption covers the deficit, the wait is # legitimate backpressure. deficit = max(0, s.bytes_remaining - conn.connection_window_available) peer_consumption = conn.total_peer_consumption(exclude=stream_id) if conn.connection_window_available >= s.bytes_remaining: return "backpressure" blocked_for = now - s.blocked_since starve_threshold = max(consumer_read_gap, neighbor_drain_estimate) if blocked_for > starve_threshold and peer_consumption > 0: # Window is exhausted AND a neighbor is actively consuming it. # This is starvation: forward progress depends on another tenant. raise McpStreamStarvationError( f"stream {stream_id} (tenant={s.tenant}) starved for " f"{blocked_for:.3f}s: connection window={conn.connection_window_available}B, " f"remaining={s.bytes_remaining}B, peer_consumption={peer_consumption}B. " f"Abort and re-establish on a fresh connection; do not retry in place." ) if blocked_for > starve_threshold and peer_consumption == 0: # Window exhausted but no peer is consuming it: transport stall. return "transport_stall" return "backpressure" def handle_blocked_stream(conn: ConnectionState, stream_id: str, now: float) -> str: """Top-level handler. Enforces the invariant that a stream's progress depends only on its own consumer. On starvation, releases the stream's lease and forces re-establishment.""" verdict = classify_blocked_write( conn, stream_id, now, consumer_read_gap=0.25, neighbor_drain_estimate=0.50, ) if verdict == "starvation": # Unreachable: classify_blocked_write raises on starvation. raise McpStreamStarvationError( f"invariant violated: starvation returned as verdict for {stream_id}" ) if verdict == "transport_stall": # Tear down the connection; all streams on it are suspect. del conn.streams[stream_id] return "abort_connection" return "wait" ```