GeezerVison is showing github.com — id(protocol): MetaProtocol close-drain is unbounded — Phase-2 handlers carry no deadline, so accept() may never return after peer close (and its doc says streams are stopped) · Issue #10400 · developing-today/code
id(protocol): MetaProtocol close-drain is unbounded — Phase-2 handlers carry no deadline, so accept() may never return after peer close (and its doc says streams are stopped) #10400DescriptionFinding
PR #4240 bounded MetaProtocol's network phases (60s read/write deadlines, 16-stream cap), but the connection-close path it introduced is unbounded: when the peer closes, accept_connection drains every admitted stream task to completion, and a stream stuck in Phase 2 — the request handler, which is deliberately not wrapped in the deadline — makes that drain, and therefore accept(), never return.
On current main (pkgs/id/crates/id-sync/src/protocol.rs, fb124d8):
accept_connection (lines 1191–1203): after the accept loop breaks, while let Some(result) = streams.join_next().await drains all admitted handlers with no overall deadline.
- The drain comment (lines 1191–1197) argues termination from the wrong premise: "Each handler's network phases stay bounded by the stream deadline, so this drain terminates." The handler itself is not a network phase.
handle_stream Phase 2 (lines 1230–1240) states the handler is "deliberately NOT wrapped in the deadline" because handlers perform non-transactional mutations — a sound reason not to cancel a mutation, but it means a handler that wedges (a contended store/tag lock, a hung filesystem call inside FileOps/TagStore, a future handler that awaits something slow) blocks the drain forever.
- The
ProtocolHandler::accept doc (lines 1267–1270) says the opposite of the implementation: "active streams are stopped when the peer closes the connection." They are not stopped; they are awaited, indefinitely.
Net effect: one wedged handler on a closing connection pins the protocol-handler task forever — graceful router/endpoint shutdown for that connection never completes, and the task, its semaphore permits and the connection state are never released. The failure is silent: nothing logs that the drain is stuck.
Evidence
- Source PR: id(protocol): bound concurrent MetaProtocol streams (fix #2086) #4240 — id(protocol): bound concurrent MetaProtocol streams (fix #2086) #4240 (merge commit
a205ae3bd38cd19f3bcfc1de64699d6e63c6ec57, confirmed ancestor of current main, compare status ahead). It fixed id(protocol): MetaProtocol accept is sequential with no stream deadline — one idle or trickling stream stalls every meta request on the connection #2086 (serial stream handling, no deadline) by introducing the concurrent accept loop, the per-phase deadlines, and this drain.
- Current main
fb124d87f7c01523499635dfc4910dab92ad9f79, pkgs/id/crates/id-sync/src/protocol.rs: accept_connection at line 1155, drain loop at 1198–1202, Phase-2 no-deadline comment at 1230–1235, contradictory accept doc at 1267–1270 — all read directly from main this run.
- The targeted tests id(protocol): bound concurrent MetaProtocol streams (fix #2086) #4240 shipped (now in
pkgs/id/crates/id-cli/src/protocol.rs tests) cover a Phase-1 stalled read stream and excess-stream reset. No test covers a handler that stalls in Phase 2 while the connection is closing, and no CI path executes that scenario.
Runtime verification (verification_class: runtime-gap/high-risk)
Result: inconclusive.
- Commit examined:
fb124d87f7c01523499635dfc4910dab92ad9f79 (current main).
- Why no reproduction: a deterministic Phase-2 stall cannot be injected from outside the crate without modifying application code —
MetaProtocol::handle is a concrete inherent method whose arms are local blob/tag/file operations with no stall seam, test double, or peer-controlled await; the verification rules for this class forbid modifying application code and forbid running the test on the sandbox. The two existing narrow tests (stalled read, excess streams) exercise Phase 1 and admission, not the drain.
- What was verified instead: the drain loop, the Phase-2 exemption, and the contradictory doc were read verbatim on current main (file:line above), and the shipped test set was enumerated — the Phase-2-stall-at-close scenario is not among them.
Why it matters
#4240's whole purpose was bounding how long a bad peer can pin server resources. The read/write phases are bounded, but the lifecycle endpoint of the connection is not: after the peer has already gone away, a single stuck handler converts a bounded connection into an unbounded shutdown hang. Shutdown paths are exactly where operators and supervisors (systemd, the router's shutdown future) wait — a hang there wedges deploys and restarts, not just one request.
Acceptance criteria
- The close-drain is bounded or supervised: e.g. an overall drain deadline after which remaining stream tasks are aborted between requests (never mid-mutation at a known-unsafe point), or the drain is detached from
accept()'s return with the stuck state logged — any design that makes accept()'s post-close lifetime finite and observable, with the trade-off against the mid-mutation-cancellation hazard (id(protocol): bound concurrent MetaProtocol streams (fix #2086) #4240's Phase-2 rationale) stated in the code.
- The
accept() doc comment matches the implemented close behavior.
- A regression test covers the scenario: a handler still in flight when the peer closes, with the connection's accept task completing (or the stuck drain being surfaced) within a bounded time; the existing stalled-read and excess-stream tests keep passing.
- Handlers that finish normally during the drain keep their current drain-to-completion behavior (no regression to aborting healthy in-flight mutations on close).
Found by pr-diff-review lane B reviewing PR #4240 against current main. Dedupe: issue searches (MetaProtocol drain, accept_connection) returned no issues; no open or closed issue covers the unbounded close-drain. Activityadded kind/bugSomething isn't working (prefixed form of the classic bug label) task/triageQueue packet kind: verify, reproduce, and route this item app/idPackage/app: id (pkgs/ or apps/ in this repo) on Nov 14, 2026developing-today commented on Nov 14, 2026 dezren39 commented on Nov 14, 2026 agent-note:v1
Agent: pr-diff-review-b
State: filed
Repo: developing-today/code
Source PR: #4240 (#4240, merged a205ae3); fixes #2086 (CLOSED)
Finding: PR #4240's MetaProtocol accept rewrite drains admitted stream tasks unboundedly on peer close (pkgs/id/crates/id-sync/src/protocol.rs:1198-1202 on main); Phase 2 handlers are deliberately deadline-free (:1230-1240), so the drain comment's termination claim (:1191-1197) does not hold and accept() may never return; the accept() doc (:1267-1270) says streams are "stopped" on close, the opposite of the drain.
Verified against main: fb124d8 (contents read of id-sync protocol.rs on main; PR #4240 merge confirmed ancestor, compare ahead). Runtime verification (runtime-gap/high-risk): INCONCLUSIVE — no deterministic Phase-2 stall can be injected without modifying application code (handle() is a concrete inherent method over local store/tag ops, no stall seam); existing targeted tests cover Phase-1 stalled read + excess streams only (now in id-cli protocol tests).
Evidence: hidden_files/pr-review-b-2026-11-14-1718-code/issue-4240-drain-body.md + diff-4240.patch + main-protocol-sync.rs dezren39 commented on Nov 14, 2026
state: triaged
task: 17336
lane: code-c
worker: repo-worker-code
Triage of issue #10400 (MetaProtocol close-drain unbounded, PR #4240 residual):
- Work kind: small-fix (task/small-fix) — a bounded change in one function of pkgs/id/crates/id-sync/src/protocol.rs plus its doc comment and regression tests in the same file.
- Priority: priority/normal (already present) — a lifecycle/concurrency bound gap: one wedged Phase-2 handler can hang a connection's graceful shutdown indefinitely and silently, but triggering it needs a handler that wedges on local contention; no data-loss path is claimed.
- Effort: effort/m — the drain bound itself is small, but the mid-mutation-cancellation trade-off must be stated in code and the regression test needs a drain seam (the issue's verification was inconclusive precisely because no stall seam exists in the concrete handler).
- First concrete step: bound the post-close drain in accept_connection with an overall deadline (2x the 60s stream deadline), factored as a testable drain unit; on expiry, log the stuck count at warn and abort the remainder. Fix the accept() doc, which currently claims streams are stopped on close (the opposite of the drain).
- Acceptance check: the issue's four criteria — bounded/observable post-close lifetime with the trade-off stated in code; doc matches behavior; a regression test covers a handler still in flight at peer close surfacing within bounded time while the existing stalled-read and excess-stream tests keep passing; handlers that finish normally keep drain-to-completion behavior.
The fix is in this packet's scope, so it proceeds in the same session (queue task 17336) rather than splitting a follow-on. dezren39 commented on Nov 14, 2026
state: done
task: 17336
lane: code-c
worker: repo-worker-code
Issue #10400 is FIXED and CLOSED by PR #10404, merged as 83a97df (2026-11-14T23:47:44Z).
The close-drain in MetaProtocol::accept_connection is now bounded overall by META_DRAIN_DEADLINE (120s = 2x the stream deadline) via the factored drain_streams unit: handlers that finish keep drain-to-completion; on expiry the stuck count is logged at warn and the remainder aborted, with the mid-mutation-cancellation trade-off stated in code. The accept() doc now matches the implemented behavior. All four acceptance criteria are met; verification: cargo test -p id-sync --lib 128 passed, cargo test -p id-cli --lib protocol:: 21 passed (existing stalled-read and excess-stream tests keep passing), including the two new oracle tests drain_streams_completes_when_handlers_finish and drain_streams_times_out_and_aborts_wedged_handler.
Codex disposition for PR #10404: the Codex review FAILED TO RUN (usage limits reached, per its summary comment at 23:47:08Z) and produced no inline findings — there were no findings to disposition.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|