Skip to content

WebKit: WebRTC DataChannel stuck in "connecting" state when upgrading from WebSocket relay connection #3347

@NiKrause

Description

@NiKrause

Description

WebKit (Safari/Playwright/DuckDuckGo) fails to establish WebRTC connections when upgrading from an initial WebSocket relay connection. The WebRTC PeerConnection is eventually successfully created, but the DataChannel never transitions from "connecting" to "open" state, resulting in a timeout after 5 seconds.

Works correctly in Firefox and Chrome/Chromium (see tests)

This issue is specific to the WebSocket bootstrap → WebRTC upgrade path.
Creating a WebRTC upgrade from a WebRTC-direct connections works fine in WebKit.

Environment

Browser: WebKit (Safari/Playwright WebKit build)
OS: macOS

libp2p version: 3.0.2 (via js-libp2p-examples/yjs-libp2p example)
Transports: WebSockets, WebRTC, WebRTC-Direct, Circuit Relay v2
Services: DCUTR enabled

Does NOT upgrade to webrtc when using a websocket relay

npx playwright test --project=webkit --grep "WebSocket bootstrap"

Does upgrade to webrtc when using a webrtc-direct (private-to-public) relay

npx playwright test --project=webkit --grep "WebRTC-Direct Bootstrap" (does upgrade to webrtc)

npm run test:chrome (does upgrade to webrtc)
npm run test:firefox (does upgrade to webrtc)

Steps to Reproduce

  1. Configure libp2p with transports enabled:
const libp2pNode = await createLibp2p({
 addresses: {
   listen: ['/p2p-circuit', '/webrtc']
 },
 transports: [
   webSockets(),
   webRTCDirect(),
   webRTC(),
   circuitRelayTransport()
 ],
 services: {
   dcutr: dcutr(),
   // ... other services
 }
  1. Bootstrap two browser instances using WebSocket addresses to connect to a relay server
  2. Both browsers successfully connect to relay via WebSocket
  3. DCUTR attempts to upgrade the relayed connection to direct WebRTC
  4. WebRTC connection initiates but DataChannel times out (green webrtc badge appears in the yjs example app)

Expected Behavior

WebRTC DataChannel should transition from "connecting" → "open"
Direct WebRTC connection should be established between peers

Actual Behavior (WebKit Only)

The WebRTC connection is created but the DataChannel never opens:

[Debug] libp2p:webrtc:connection:inbound:c5hq761762194022635 successfully upgraded connection
[Debug] libp2p:webrtc:connection:inbound:c5hq761762194022635:muxer:outbound:0 
  channel ready state is "connecting" and not "open", 
  waiting for "open" event before sending data

after 5 seconds:

[Debug] libp2p:webrtc:connection:inbound:c5hq761762194022635:muxer:outbound:0:error 
  abort with error - The operation timed out.
[Debug] libp2p:webrtc:connection:inbound:c5hq761762194022635 transport closed

DCUTR Failures

DCUTR also fails with:

[Debug] libp2p:dcutr B had no dialable multiaddrs in [...] (18)DCUtR connect message had no dialable multiaddrs

All 3 DCUTR attempts fail with stream resets.

See:
#2007
#1808

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions