fix(source): wait for the broadcast announcement instead of racing it#49
fix(source): wait for the broadcast announcement instead of racing it#49appkanamiru wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Sorry @appkanamiru, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Walkthroughsrc/moq-source.cpp is modified to consume announced broadcasts asynchronously via moq_origin_consume_announced instead of the synchronous moq_origin_consume. A new consume_announced_task field tracks the pending task handle for cancellation and cleanup. A new on_broadcast_ready callback manages the announced-consume lifetime, handles success/error/terminal cases, sets the consume handle, and initiates catalog subscription via moq_consume_catalog. Disconnect logic and related log/comment text are updated to reflect the new asynchronous flow. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify code
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/moq-source.cpp`:
- Around line 668-669: Thread the per-task consume-announced state through
on_broadcast_ready so stale callbacks cannot overwrite newer context. Capture
the task token and expected generation when calling
moq_origin_consume_announced, pass them via the callback state, and update
on_broadcast_ready to verify the callback still matches ctx before clearing
consume_announced_task or attaching the broadcast. Ignore late callbacks from
older reconnecting/closed tasks instead of using ctx->generation at callback
time.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Problem
moq_source_start_consumecalls the synchronousmoq_origin_consumeimmediately after the session connects (first
on_session_status). At thatmoment the announcement usually hasn't propagated, so the lookup loses the
race and returns
BroadcastNotFound (-24), and the source blanks withoutretrying. A MoQ Source pointed at a live broadcast just stays black:
The web player works against the same broadcast because it waits for the
announcement.
Fix
Use
moq_origin_consume_announced, which waits for the announcement anddelivers the broadcast handle via a callback (
on_broadcast_ready), thensets up the catalog subscription exactly as before. libmoq's own docs
recommend this call "right after moq_session_connect to avoid racing
announcement gossip." The wait handle is stored so
disconnectcan cancelit; the ref-counting and generation/shutting-down guards mirror the existing
paths.
Requires libmoq exporting
moq_origin_consume_announced/moq_origin_consume_announced_close(present in 0.3.10; builds cleanly with--libmoq-release 0.3.10).Test
Waiting for broadcast announcementthenConsuming announced broadcast.