Skip to content

relay: install the local forwarder chain on subscribe-created tracks - #546

Merged
afrind merged 1 commit into
fix/lf-subscribe-setup-racefrom
fix/lf-subscribe-created-track-chain
Aug 11, 2026
Merged

relay: install the local forwarder chain on subscribe-created tracks#546
afrind merged 1 commit into
fix/lf-subscribe-setup-racefrom
fix/lf-subscribe-created-track-chain

Conversation

@afrind

@afrind afrind commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

A track created by its first subscriber left no entry in the publisher thread's LocalForwarderRegistry, so a subscriber landing on that thread joined a separate local forwarder instead of the publisher's. First subscriber setup now calls installPublisherForwarder on the publisher executor with removeOnEmpty=true, so the entry is there to find and is dropped with the last subscriber.

The initial state for the requesting subscriber is captured from the publisher forwarder, so subscribers joining an existing attachment also get the most recent largest and extensions.


This change is Reviewable

@akash-a-n akash-a-n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akash-a-n reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: 2 of 4 files reviewed, 1 unresolved discussion (waiting on afrind).


src/MoqxRelay.cpp line 1198 at r1 (raw file):

  }
  auto* ready = std::get_if<LocalForwarderRegistry::Ready>(&joined);
  XCHECK(ready) << "local forwarder entry still pending; a caller failed to resolve its claim: "

copilot flagged a race condition here, where the joinResult would be pending:

  1. On thread T we have an open subscribe_namespace request
  2. We get a SUBSCRIBE request on the same thread which then goes upstream and gets suspended
  3. During this suspension, we get a publish(on a different thread) that fans out thread T through acquireLocalForwarder and the joinResult would be 'pending'

@afrind afrind left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afrind made 1 comment.
Reviewable status: 2 of 4 files reviewed, 1 unresolved discussion (waiting on akash-a-n).


src/MoqxRelay.cpp line 1198 at r1 (raw file):

Previously, akash-a-n wrote…

copilot flagged a race condition here, where the joinResult would be pending:

  1. On thread T we have an open subscribe_namespace request
  2. We get a SUBSCRIBE request on the same thread which then goes upstream and gets suspended
  3. During this suspension, we get a publish(on a different thread) that fans out thread T through acquireLocalForwarder and the joinResult would be 'pending'

Aha, good find. I'm going to handle this by dropping a PUBLISH that matches an in-progress SUBSCRIBE. I think it's important because the subscription should get the pinned flag.

@afrind
afrind force-pushed the fix/lf-subscribe-created-track-chain branch from 2ec50ef to a243095 Compare August 10, 2026 22:05

@akash-a-n akash-a-n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akash-a-n reviewed 3 files and all commit messages, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on afrind).

@afrind
afrind force-pushed the fix/lf-subscribe-created-track-chain branch from a243095 to c9710fb Compare August 11, 2026 15:38
A track created by its first subscriber left no entry in the publisher
thread's LocalForwarderRegistry, so a subscriber landing on that thread
joined a separate local forwarder instead of the publisher's. First
subscriber setup now calls installPublisherForwarder on the publisher
executor with removeOnEmpty=true, so the entry is there to find and is
dropped with the last subscriber.

The initial state for the requesting subscriber is captured from the
publisher forwarder, so subscribers joining an existing attachment also
get the most recent largest and extensions.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@afrind
afrind force-pushed the fix/lf-subscribe-created-track-chain branch from c9710fb to 4807fa1 Compare August 11, 2026 15:39
@afrind
afrind merged commit 1449121 into main Aug 11, 2026
15 of 20 checks passed
@afrind
afrind deleted the fix/lf-subscribe-created-track-chain branch August 11, 2026 17:23
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.

2 participants