Repository navigation
fix(build-tools): stop one WebSocket message from crashing the self-hosted API - #5988
Conversation
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 API process down. On
a self-hosted API that needed no authentication: one message to the
WebSocket endpoint was enough.
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>
|
🚓 Slop Cop ✅ Nothing worth flagging. The diff looks consistent with the PR's stated intent and the code-style rules. Small, focused fix matching its stated intent; no integrity or style issues found. Automated, non-blocking heads-up from an LLM. It can be wrong — use your judgment. Regenerates on every push. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
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.wsserver (api-websockets-server), and its betas are published. The same change for 6.5.0 is fix(build-tools): stop one WebSocket message from crashing the self-hosted API (6.5.0) #5989.Workspace: wby-next2 · 🧹 MERGE 6.5.0 => NEXT
🤖 Generated with Claude Code
Summary by CodeRabbit