Skip to content

subscription concludes Ok(None) with a group in its range never delivered #4061

Description

@kidq330

Summary

When the session serving a subscription dies with a group still in flight, the
moq-net subscriber concludes normally: recv_group() returns Ok(None), the
same value it returns for a track that ended. The consumer cannot learn that a
group inside the range it subscribed to never arrived; the track looks like it
ended after the last group the consumer pulled.

This is about the end signal, not the loss. Whether the publisher could have
flushed before disconnecting is a separate question (it has nothing to await
today). Even a perfectly flushed publisher cannot stop a session from dying at
any moment, so the subscriber has to report that death honestly.

Expected

moq-lite, Subscribe:

The publisher closes the stream (FIN) only once every group from start to end
has been accounted for, either via a Group Stream (completed or reset) or a
SUBSCRIBE_DROP message.

and Routing:

when the serving session ends, in-flight subscriptions end with it (a reset)

A subscription therefore ends cleanly only by that gated FIN, and the session
going away is a reset. Neither happened here, and the subscriber still reports a
clean end. It should end with an error, or deliver every group.

Observed

Two tests, each with a control that keeps the session alive, on
kidq330/bug/subscription_ends_clean_with_missing_group. Both bug arms fail on main, both
controls pass.

Transport Setup Subscriber gets Should get
Mock session, in-process (moq-net, paused time, single thread, deterministic) The head group is delivered. finish_at(2), so SUBSCRIBE_END goes out. The final group opens and its first frame is delivered. Its second frame and FIN are written and the session is dropped with no await in between. The close lands, then the subscriber reads on. ["head-a", "head-b"], then Ok(None). The final group is skipped, delivered first frame included. An error, or all four frames
Real QUIC, no relay (moq-tokio) The head group is drained. The subscriber stops reading for 300 ms while the publisher writes a 4 MB final group, finish()es the track and drops the session, so the group is still behind the flow-control window at CONNECTION_CLOSE. 10 of 20 frames, then Ok(None), 10 rounds out of 10. An error, or 20 of 20
Mock session, timing variant Same as the first row, but the subscriber reads on before the close lands. ["head-a", "head-b", "tail-a"], then Err(Cancel). This is the correct signal. Today it depends on the consumer winning a race against the close.

The third row is why the mock test settles the runtime between the drop and the
read: a consumer merely slower than the network gets the silent version. Whether
a truncated track reads as an error or as complete is decided by who reads first,
not by what happened.

cd rs && cargo nextest run -p moq-net   --test subscription_end_integrity   # mock, deterministic
cd rs && cargo nextest run -p moq-tokio --test subscription_end_integrity   # real QUIC, 10 rounds

Tests: a_subscription_cut_by_the_session_close_does_not_end_clean (moq-net),
a_subscription_cut_by_the_publisher_disconnecting_does_not_end_clean
(moq-tokio), and a_finished_track_ends_clean_while_its_session_lives in each.

Impact

  • A consumer cannot distinguish "the track ended" from "my session died
    mid-track". Every downstream that trusts Ok(None) (a relay's cache, moq export, a player) treats a truncated track as complete.
  • Tail loss becomes invisible. Found while chasing missing final groups through
    moq import / moq export: the frames were gone and nothing reported it,
    because the subscriber ended clean.
  • The subscriber already has the information. The session's teardown does abort
    the track, and the timing variant shows the error reaching the consumer; the
    clean-end check just takes precedence over it.

Context

  • docs(quest): plan the JS and Rust track tail and session-death errors #4017 plans a "Session death error" quest with the goal "A reader never sees a
    clean end for a stream that was cut off." Its Rust notes cover Dropped and
    Cancel standing in for the session's error, but not that the Rust subscriber
    can report a clean end at all. This issue is that case, with a deterministic
    repro the quest can pin.

(Written by Claude Fable 5.1)

Activity

  1. added 2 commits that reference this issue on Sep 24, 2026
    f4eec54
    b26fe8c
  2. kixelated commented on Sep 28, 2026

    @kixelated
    Collaborator

    Summary of the planning decision (#4017):

    • Folded into the existing Session death error quest rather than a separate Rust-only quest. The plan added one requirement: the clean-end check must not win over the session abort. Your deterministic mock repro pins it.
    • Status: fixed in fix(net): end a track with its session's error when the session dies #4120. After SUBSCRIBE_END declares the end, a session that dies with a group below that end still in flight now ends the track with the session's error instead of Ok(None). The origin and resume layer carry that abort through too.

    (Written by Claude Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions