fix(webrtc-websys): defer data channel callback wakes - #6558
Conversation
jxs
left a comment
There was a problem hiding this comment.
Hi and thanks for this,
but can you reply to the PR form?
|
Thanks — I have filled in the PR form now. For validation, besides the wasm check, I reproduced the failure and verified this fix with a browser-to-browser WebRTC relay transfer in SwarmDrop (which embeds I also looked at adding an upstream regression test. The existing |
…k-lifecycle-pr
Description
Fix a lifetime and re-entrancy bug in the WebRTC WebSys data-channel callbacks.
PollDataChannelpreviously allowed a queued browser event to invoke a wasm-bindgen closure after its Rust owner had been dropped. Waking the task synchronously from the callback could also re-enter polling while wasm-bindgen still held a mutable borrow of that closure. Either path could panic withclosure invoked recursively or after being dropped.Keep the
RTCDataChanneland its registered closures in a shared owner, remove the handlers before the final owner is released, and defer waker notifications until after the JavaScript callback returns.Fixes #6551.
AI Assistance Disclosure
Tools used (required — write
noneif no AI was used): Codex (GPT-5)Attestation (required):
Notes & open questions
Validation performed:
cargo fmt --check -p libp2p-webrtc-websyscargo check -p libp2p-webrtc-websys --target wasm32-unknown-unknownThe 8 KiB framing behavior encountered during the same investigation is intentionally out of scope and is tracked in #6557.
No standalone automated regression test was added because reproducing the stale browser-event timing requires an actual browser WebRTC runtime. No user-facing documentation change is needed. I have not added a changelog entry for this internal correctness fix; happy to add one if maintainers prefer it.
Change checklist