libp2p / libp2p/js-libp2p

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

Open
#3,499 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

need/triage
Dominant language
TypeScript
Stars
2.6k
Forks
546
Avg merge
8h 18m
Merged PRs (30d)
16

Description

  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the webSocketToMaConn construction path in the transport-websockets package and review the reproducer described in #3497. Confirm how missing bufferedAmount is detected and how the resulting typed error should surface during dialing. Done means affected runtimes receive a clear dial-time error without replacing the missing value or weakening backpressure.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.