Repository navigation
Skip empty payload write in Sender.sendFrame - #2341
Closed
SahinurDEV wants to merge 1 commit into
Closed
SahinurDEV wants to merge 1 commit into
SahinurDEV wants to merge 1 commit into
Conversation
Empty unmasked frames were sent as two socket writes (header + zero-length payload). On some Electron arm64 kernels a zero-length write fails with EFAULT and destroys the connection. Skip the payload write when it is empty; the header already encodes length 0. Fixes websockets#2339
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.
Problem
Sender.sendFrame()writes an unmasked frame as two socket writes (header, then payload) even when the payload is empty. On Electron on some arm64 Linux kernels with a 39-bit address space,net.Socket#write()of a zero-length Buffer fails withEFAULTand destroys the socket. That kills empty server-side ping/pong/message/close()frames (including the automatic pong to an empty client ping) with close code 1006.Cause
Fix
Skip the payload write when it is empty:
The frame header already encodes length 0, so the bytes on the wire are unchanged. Masked empty frames are unaffected (they are already a single write).
Tests
Added unit tests that assert an empty unmasked ping is a single write of the header, and a non-empty unmasked ping still uses two writes. Full
test/sender.test.jspasses; suite otherwise green aside from an unrelatedEADDRINUSEflake on port 1337 in this environment.Fixes #2339