transport-websockets: dial fails on runtimes missing WebSocket.bufferedAmount
Nobody has claimed this yet.
- 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:
canSendMorestays permanentlytrue,writableNeedsDrainnever 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:
- Set up a React Native (Expo) project using
@libp2p/transport-websocketswith the standard noise + yamux stack. - Dial a Node.js libp2p node listening on
/ip4/.../tcp/.../ws. - Dial fails at
mss.selectwithTypeError: Cannot read property 'message' of undefinedfromUpgrader._encryptOutbound.
A working reproducer is described in #3497.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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