handle WebSocket implementations missing bufferedAmount#3497
Open
ernest-okot wants to merge 1 commit into
Open
handle WebSocket implementations missing bufferedAmount#3497ernest-okot wants to merge 1 commit into
ernest-okot wants to merge 1 commit into
Conversation
React Native's WebSocket implementation does not expose bufferedAmount (it's undefined). The current code in WebSocketMultiaddrConnection.sendData compares it directly with a number, which evaluates undefined < 4MB to false, marking every write as needing drain. The eventual 'close' event then makes pEvent reject with undefined, surfacing in Upgrader._encryptOutbound as the cryptic TypeError: Cannot read property 'message' of undefined. Same guard applied to checkBufferedAmount, which otherwise starts a polling task that never terminates. Testing Reproducer: a React Native Expo project using @libp2p/websockets to dial a Node.js relay. Before the fix, every dial fails at mss.select with the undefined-message error. After the fix, dial completes and noise handshake proceeds normally. Refs - React Native WebSocket source: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/WebSocket/WebSocket.js — bufferedAmount is not implemented. - MDN: bufferedAmount is required for browsers but not all WebSocket implementations conform.
Member
|
This would effectively remove all backpressure guards from the transport inside of React Native and any other environment where bufferedAmount is undefined. You're very likely to hit errors further down the road which are harder to debug. Have you tried other transports for your usecase? I'm not able to find a good way to handle this atm. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title
Description
React Native's WebSocket implementation does not expose bufferedAmount (it's undefined). The current code in WebSocketMultiaddrConnection.sendData compares it directly with a number, which evaluates undefined < 4MB to false, marking every write as needing drain. The eventual 'close' event then makes pEvent reject with undefined, surfacing in Upgrader._encryptOutbound as the cryptic TypeError: Cannot read property 'message' of undefined.
Same guard applied to checkBufferedAmount, which otherwise starts a polling task that never terminates.
Reproducer: a React Native Expo project using @libp2p/websockets to dial a Node.js relay. Before the fix, every dial failed at
mss.selectwith an undefined message error. After the fix, dial completes and noise handshake proceeds normally.Refs
Change checklist