Repository navigation
fix(build-tools): stop one WebSocket message from crashing the self-hosted API (6.5.0) - #5989
Merged
Merged
Conversation
….5.0)
The API bundle replaced ws's optional native `bufferutil` module with an
empty one (`resolve.fallback: { bufferutil: false }`). ws loads it inside
a try/catch, and an empty module loads without throwing, so ws switched
to `bufferUtil.unmask`, which is undefined. Every client frame is masked,
so any incoming WebSocket message of 32 bytes or more threw
"bufferUtil.unmask is not a function" and took the self-hosted API
process down.
bufferutil is now left out with an IgnorePlugin entry instead, like
jsdom's `canvas`. An ignored module throws MODULE_NOT_FOUND when
required, ws catches that, and it keeps its JavaScript mask/unmask.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
On a self-hosted API, any incoming WebSocket message of 32 bytes or more crashed the API process with
TypeError: bufferUtil.unmask is not a function. The process exited, and the API stayed down until it was restarted.Cause
The function bundle config (
build-tools/bundling/function/createRsbuildConfig.js) setresolve.fallback: { bufferutil: false }to leave outws's optional nativebufferutilmodule. Afalsefallback makes rspack bundle an empty module in its place.wsloadsbufferutilinside atry/catchand falls back to its own JavaScript only when the require throws. The empty module loads fine, sowsswitchedmask/unmasktobufferUtil.mask/bufferUtil.unmask, which are undefined. Client frames are always masked, andwsuses the nativeunmaskfor payloads of 32 bytes or more, so every message that size threw inside the socket's data handler. Thewsserver runs only in the self-hosted (standalone) API. On AWS, WebSockets go through API Gateway.Fix
bufferutilis now left out with anIgnorePluginentry, the same way the config already leaves out jsdom's optionalcanvas. An ignored module throwsMODULE_NOT_FOUNDwhen required,wscatches that, and it keeps its JavaScript implementation. Theresolve.fallbackentry is removed.bufferutilwas the only module the bundle ignored this way.Testing
MODULE_NOT_FOUNDforbufferutil, and the same message sent three times leaves the API answering 200. The admin's own WebSocket connection still connects and works.next, where it was verified as described above.Workspace: wby-next2 · 🧹 MERGE 6.5.0 => NEXT
🤖 Generated with Claude Code