Skip to content

fix(qmux): release stream waiters at terminal teardown - #437

Merged
kixelated merged 3 commits into
mainfrom
fix/qmux-terminal-streams
Oct 22, 2026
Merged

kixelated merged 3 commits into
mainfrom
fix/qmux-terminal-streams

Conversation

@kixelated

@kixelated kixelated commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closing a session with an unfinished stream leaves read_chunk, RecvStream::closed, and SendStream::closed pending while any Session handle remains alive. The backend exits, but the shared stream table still owns their channel senders. A receiver can consume all buffered bytes and then wait forever instead of observing closure. This blocks the no-timeout receive drain in moq-dev/moq#5762.

Clear both stream tables at terminal reader teardown, closing send credit and releasing channel senders. Serialize local registration against the same terminal flag so an open that claimed credit before teardown cannot restore a sender afterwards. Buffered data and received FINs remain readable. Public API and wire format are unchanged; no version bump or release is included.

The exact TCP reproducer also fails on main c2e93e4, close draft #412 (82527d2), and counter draft #435 (5a9c692). Their 0.5 backports #413/#436 and the socket-stat descriptor teardown quest address separate behavior.

Validation:

  • Three deterministic no-timeout regressions fail before the fix. Five focused unit cases pass with it, including FIN preservation and rejection of late registration.
  • Real TCP uni/bidi loopback passes for QMux01 and QMux02, retaining Session handles through backend shutdown.
  • The exact previously timed-out moq-gst a_closed_publisher_session_resumes_on_the_next_start test passes in 2.565s with an isolated temporary source override on moq#5762. Its branch, config, and lockfile remain unchanged.
  • Pinned-Nix just fix, just check, and just test pass on clean head 601e7fb. Checks include native/WASM clippy and feature powersets; tests include 378 Rust tests/doctests, 158 TypeScript tests, and both Rust/TypeScript WebSocket interop tests.

moq-dev/moq#5762 still needs this fix reviewed and merged, a published qmux release containing it, then a dependency update and clean full gates/interop. This PR does not publish or pin unpublished code.

(written by GPT-6)

kixelated and others added 2 commits October 16, 2026 14:07
Co-Authored-By: GPT-6 <noreply@openai.com>
Drop retained stream channel senders and serialize registration against terminal cleanup so unfinished streams drain and close while Session handles remain alive.

Co-Authored-By: GPT-6 <noreply@openai.com>
# Conflicts:
#	rs/qmux/src/session.rs
@kixelated

Copy link
Copy Markdown
Collaborator Author

Merged main (9432b0a) to resolve the conflict with #440's stream occupancy counts. Streams::open now registers through insert_send/insert_recv, and Streams::close also zeroes the occupancy counts, matching the emptied tables (stats() already reports zero once closed).

Rechecked against moq-dev/moq#5762 merged with current moq main, using a local, uncommitted [patch] of this branch (qmux and web-transport-trait):

  • Without it: the two moq-gst tests a_closed_publisher_session_resumes_on_the_next_start and a_moqsink_restart_keeps_pads_when_caps_arrive_at_different_times time out.
  • With it: 4 of 4 full moq-gst runs pass (199/199), and a 10x stress of those two tests passes.
  • cargo test -p qmux --all-features, cargo fmt --check, and clippy -D warnings pass here.

moq-dev/moq#5762 consumes this through a qmux patch release and a version bump, not a [patch].

(Written by Claude Opus 5.5)

@kixelated
kixelated marked this pull request as ready for review October 22, 2026 00:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T00:13:03.119502Z 9432b0a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 786312cb-7b20-4c21-8b42-a5fca92e6e76
📥 Commits

Reviewing files that changed from the base of the PR and between 33269b1 and 9432b0a.

📒 Files selected for processing: 2
  • rs/qmux/src/session.rs
  • rs/qmux/tests/close.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

The shared Streams state now tracks closure, rejects late stream registration, and closes stream resources during session teardown. The open_uni and open_bi APIs return the session close reason if teardown prevents registration. Tests cover buffered data and FIN preservation, closure of unfinished streams, and behavior across QMux versions 0.1 and 0.2.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 9432b

Terminal teardown preserves the intended close-reason behavior for concurrent stream opens. No merge-blocking issue was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the terminal teardown bug, the implemented fix, preserved behavior, validation, and release constraints. It is directly related to the changeset.
Title check Passed The title clearly and concisely identifies the main change: releasing stream waiters during terminal teardown.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.99.0)

Clippy execution timed out

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kixelated
kixelated merged commit f35d3a2 into main Oct 22, 2026
3 checks passed
@kixelated
kixelated deleted the fix/qmux-terminal-streams branch October 22, 2026 01:06
This was referenced Oct 22, 2026
kixelated added a commit to moq-dev/moq that referenced this pull request Oct 22, 2026
qmux 0.6.5 (moq-dev/web-transport#437) ends receive-stream reads at
session teardown, which the close-tail drain relies on. It uses trait
API from web-transport-trait 0.5.1, so the lockfile moves that too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit to spotdemo4/web-transport that referenced this pull request Oct 23, 2026
Resolve conflicts with moq-dev#437 and moq-dev#453:

- rs/qmux/src/session.rs: keep main's Streams::open, which seeds a new
  stream's send credit and refuses registration after teardown, and adapt
  its increase_max call to the infallible signature.
- quest/a0/README.md: drop both the Noq close cancellation entry (landed
  in moq-dev#453) and the QMux credit updates entry (completed here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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