Skip to content

wasm-node: don't open a substream on a closed connection - #3327

Merged
lrubasze merged 2 commits into
mainfrom
lrubasze/fix-open-substream-on-closed-peer-connection
Aug 5, 2026
Merged

wasm-node: don't open a substream on a closed connection#3327
lrubasze merged 2 commits into
mainfrom
lrubasze/fix-open-substream-on-closed-peer-connection

Conversation

@lrubasze

@lrubasze lrubasze commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #3325
Fixes DOTLI-B9

Problem

An RTCPeerConnection can move to closed before its connectionstatechange event is dispatched. Until the event runs, smoldot still believes the connection is alive and can ask to open a substream; createDataChannel() then throws an uncaught InvalidStateError. Connection-level twin of #3322, observed in production (smoldot 3.3.2, Chrome 151, Sentry DOTLI-B9).

Fix

openOutSubstream is now a no-op when signalingState is closed — the pending state-change event resets the connection anyway. Same shape as the send guard from #3324.

Test

New browser-only e2e test webrtc_open_after_pc_close: closes one connection mid-substream-burst and delivers the state-change notification 2s late (browsers fire no events for a local close(), so the late event is synthesized), so smoldot's next openOutSubstream lands on a closed connection. Without the guard the client crashes; with it it must sync normally. A wrapped signalingState getter asserts the race was actually exercised. CI entry commented out until browser test execution is re-enabled (as with the other webrtc_* tests).

@lrubasze
lrubasze requested a review from a team August 5, 2026 09:17
@lrubasze
lrubasze merged commit b6bd495 into main Aug 5, 2026
39 checks passed
@lrubasze
lrubasze deleted the lrubasze/fix-open-substream-on-closed-peer-connection branch August 5, 2026 16:17
@lrubasze lrubasze mentioned this pull request Aug 7, 2026
lrubasze added a commit that referenced this pull request Aug 7, 2026
This is to:
- publish `smoldot-v3.4.0` npm.
- publish crates `smoldot-light v2.0.0`, `smoldot v2.2.0`

## Changes

### Added

- Implement the
[RFC-0163](https://github.com/polkadot-fellows/RFCs/blob/main/text/0163-ec-host-functions.md)
elliptic curve host functions: scalar multiplication and multi-scalar
multiplication on bandersnatch (`ed_on_bls12_381_bandersnatch`), and
scalar multiplication, multi-scalar multiplication, multi Miller loop
and final exponentiation on BLS12-381. This lets smoldot execute
runtimes that verify bandersnatch ring-VRF proofs (proof-of-personhood
chains). The remaining RFC-0163 functions (Pallas, Vesta) are registered
but unimplemented.
([#3331](#3331); fixes
[#3328](#3328))

### Fixed

- Fix a panic (`assertion failed: task.event_pending_send.is_none()` in
debug builds) or a silently lost connection event (release builds, later
causing a sync service panic on an unmatched `Disconnected`) when a peer
ban raced with a network event that was still being delivered to
subscribers. ([#3314](#3314);
fixes [#3312](#3312))
- No longer crash with an uncaught `InvalidStateError` when sending on
an `RTCDataChannel` that left the `open` state before its `close` event
was delivered; the send is skipped, since the pending `close` event
resets the stream anyway.
([#3324](#3324); fixes
[#3322](#3322))
- In remote-instance mode, no longer crash with an uncaught `TypeError`
when a message addressed to the first substream of a WebRTC connection
(stream id 0) raced with that substream's reset: stream id 0 was
accidentally exempt from the stale-message check.
([#3326](#3326); related to
[#3322](#3322))
- No longer crash with an uncaught `InvalidStateError` when opening a
substream on an `RTCPeerConnection` that moved to `closed` before its
`connectionstatechange` event was delivered.
([#3327](#3327); fixes
[#3325](#3325))
- Fix a panic in the connection task when the remote resets an inbound
notifications substream while a message about that substream is still in
flight (a duplicate reject, or a close right after an accept).
([#3329](#3329); fixes
[#3304](#3304))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants