Skip to content

transport-websockets: dial fails on runtimes missing WebSocket.bufferedAmount #3499

Description

@tabcat
  • Version: @libp2p/transport-websockets 10.1.12
  • Platform: React Native (iOS + Android)
  • Subsystem: transport-websockets

Severity:

High — dialing over the WebSocket transport fails on affected runtimes.

Description:

WebSocketMultiaddrConnection in @libp2p/transport-websockets reads bufferedAmount to manage backpressure. React Native's WebSocket declares the property but never assigns it (RN#33810) — so undefined < maxBufferedAmount is false, every write marks the stream as needing drain, drain is never emitted, and the noise handshake fails with a cryptic TypeError: Cannot read property 'message' of undefined from Upgrader._encryptOutbound.

#3497 proposed substituting 0 when bufferedAmount is missing, but that silently disables backpressure for affected connections:

  • canSendMore stays permanently true, writableNeedsDrain never flips, the muxer never pauses pushing data to streams
  • Application code can pile unbounded bytes into the runtime's internal queue
  • On Android, OkHttp closes the connection with code 1001 once its 16 MiB queue overflows (RN#56471)

Proposed resolution: detect missing bufferedAmount at construction in webSocketToMaConn and throw a typed error naming the limitation. Surfaces a clear dial-time error instead of the silent failure, without regressing backpressure.

Workaround today: @libp2p/transport-tcp works in React Native with react-native-tcp-socket + Metro polyfills — see the ipfs-shipyard demo.

Steps to reproduce the error:

  1. Set up a React Native (Expo) project using @libp2p/transport-websockets with the standard noise + yamux stack.
  2. Dial a Node.js libp2p node listening on /ip4/.../tcp/.../ws.
  3. Dial fails at mss.select with TypeError: Cannot read property 'message' of undefined from Upgrader._encryptOutbound.

A working reproducer is described in #3497.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions