webrtc-websys: RTCDataChannel callbacks can panic after stream teardown
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.6k
- Forks
- 1.3k
- Avg merge
- 8h 47m
- Merged PRs (30d)
- 19
Description
Summary
In browsers, libp2p-webrtc-websys can panic from an RTCDataChannel event callback after its Rust stream has been torn down:
Uncaught Error: closure invoked recursively or after being dropped
... at RTCDataChannel.<callback>
Root cause
PollDataChannel registers Rust wasm-bindgen closures as persistent RTCDataChannel event handlers. A browser may dispatch an event that was queued before the final Rust stream clone is dropped. If the corresponding Closure has already been released, the stale JavaScript handler invokes a dropped closure.
Calling AtomicWaker::wake() synchronously from the Web API callback can also re-enter polling while wasm-bindgen still holds a mutable borrow of that callback closure.
Proposed fix
- Keep the DataChannel and all registered event callbacks in a shared owner for the lifetime of the final stream clone.
- Detach each browser event handler before that owner releases its closures.
- Defer waker notifications until the Web API callback has returned.
Validation
A focused implementation is available in #6558. It passes the wasm32 build check and removes the browser callback exception in browser-to-browser WebRTC relay transfer testing; the same transfer completes successfully.
The relay frame-size failure found during this investigation is independent and tracked separately in #6557.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with PollDataChannel and compare the focused implementation described in #6558. Run the wasm32 build check and browser-to-browser WebRTC relay transfer testing; done means the browser callback exception is gone and the transfer completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- audio-video-rtc, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100