[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EK5Z2A2B62MYVXPZHE8BZP":3,"skill-same:01M6EK5Z2A2B62MYVXPZHE8BZP":64},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":30,"linkOnly":31,"markdownContent":32,"markdownBody":33,"frontMatter":34,"refName":35,"commitSha":36,"skillDirectory":37,"forksCount":38,"repositoryHtmlUrl":39,"repositoryHomepageUrl":40,"ownerHtmlUrl":41,"ownerBlogUrl":6,"ownerDescription":42,"updatedAt":43,"install":44,"resources":57},"01M6EK5Z2A2B62MYVXPZHE8BZP","debugging-websocket-issues",null,"Use when seeing WebSocket errors like \"Invalid frame header\", \"RSV1 must be clear\", or \"WS_ERR_UNEXPECTED_RSV_1\" - covers multiple WebSocketServer conflicts, compression issues, and raw frame debugging techniques","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fagentworkforce\u002Fdebugging-websocket-issues\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29],"debugging","issues","websocket","debugging websocket issues","compression","node","use","conflicts","invalid","clear","websocket, debugging, ws, node","2026-11-10 10:12:30",false,"---\nname: debugging-websocket-issues\ndescription: Use when seeing WebSocket errors like \"Invalid frame header\", \"RSV1 must be clear\", or \"WS_ERR_UNEXPECTED_RSV_1\" - covers multiple WebSocketServer conflicts, compression issues, and raw frame debugging techniques\ntags: websocket, debugging, ws, node\n---\n\n# Debugging WebSocket Issues\n\n## Overview\n\nWebSocket \"invalid frame header\" errors often stem from raw HTTP being written to an upgraded socket, not actual frame corruption. The most common cause is multiple `WebSocketServer` instances conflicting on the same HTTP server.\n\n## When to Use\n\n- Error: `Invalid WebSocket frame: RSV1 must be clear`\n- Error: `WS_ERR_UNEXPECTED_RSV_1`\n- Error: `Invalid frame header`\n- WebSocket connects then immediately disconnects with code 1006\n- Server logs success but client receives garbage data\n\n## Quick Reference\n\n| Symptom | Likely Cause | Fix |\n|---------|--------------|-----|\n| RSV1 must be clear | Multiple WSS on same server OR compression mismatch | Use `noServer: true` mode |\n| Hex starts with `48545450` | Raw HTTP on WebSocket (0x48='H') | Check for conflicting upgrade handlers |\n| Code 1006, no reason | Abnormal closure, often server-side abort | Check `abortHandshake` calls |\n| Works isolated, fails in app | Something else writing to socket | Audit all upgrade listeners |\n\n## The Multiple WebSocketServer Bug\n\n### Problem\n\nWhen attaching multiple `WebSocketServer` instances to the same HTTP server using the `server` option:\n\n```typescript\n\u002F\u002F ❌ BAD - Both servers add upgrade listeners, causing conflicts\nconst wss1 = new WebSocketServer({ server, path: '\u002Fws' });\nconst wss2 = new WebSocketServer({ server, path: '\u002Fws\u002Fother' });\n```\n\n**What happens:**\n1. Client connects to `\u002Fws`\n2. BOTH upgrade handlers fire (Node.js EventEmitter calls all listeners)\n3. `wss1` matches path, handles upgrade successfully\n4. `wss2` doesn't match, calls `abortHandshake(socket, 400)`\n5. Raw `HTTP\u002F1.1 400 Bad Request` written to the now-WebSocket socket\n6. Client receives HTTP text as WebSocket frame data\n7. First byte `0x48` ('H') interpreted as: RSV1=1, opcode=8 → invalid frame\n\n### Solution\n\nUse `noServer: true` and manually route upgrades:\n\n```typescript\n\u002F\u002F ✅ GOOD - Single upgrade handler routes to correct server\nconst wss1 = new WebSocketServer({ noServer: true, perMessageDeflate: false });\nconst wss2 = new WebSocketServer({ noServer: true, perMessageDeflate: false });\n\nserver.on('upgrade', (request, socket, head) => {\n  const pathname = new URL(request.url || '', `http:\u002F\u002F${request.headers.host}`).pathname;\n\n  if (pathname === '\u002Fws') {\n    wss1.handleUpgrade(request, socket, head, (ws) => {\n      wss1.emit('connection', ws, request);\n    });\n  } else if (pathname === '\u002Fws\u002Fother') {\n    wss2.handleUpgrade(request, socket, head, (ws) => {\n      wss2.emit('connection', ws, request);\n    });\n  } else {\n    socket.destroy();\n  }\n});\n```\n\n## Debugging Techniques\n\n### Raw Frame Inspection\n\nHook into the socket to see actual bytes received:\n\n```typescript\nws.on('open', () => {\n  const socket = ws._socket;\n  const originalPush = socket.push.bind(socket);\n\n  socket.push = function(chunk, encoding) {\n    if (chunk) {\n      console.log('First 20 bytes (hex):', chunk.slice(0, 20).toString('hex'));\n      const byte0 = chunk[0];\n      console.log(`FIN: ${!!(byte0 & 0x80)}, RSV1: ${!!(byte0 & 0x40)}, Opcode: ${byte0 & 0x0f}`);\n\n      \u002F\u002F Check if it's actually HTTP text\n      if (chunk.slice(0, 4).toString() === 'HTTP') {\n        console.log('*** RECEIVED RAW HTTP ON WEBSOCKET ***');\n      }\n    }\n    return originalPush(chunk, encoding);\n  };\n});\n```\n\n### Key Hex Patterns\n\n- `81` = FIN + text frame (normal)\n- `82` = FIN + binary frame (normal)\n- `88` = FIN + close frame (normal)\n- `48545450` = \"HTTP\" - raw HTTP on WebSocket (bug!)\n- `c1` or similar with bit 6 set = compressed frame (RSV1=1)\n\n## Common Mistakes\n\n| Mistake | Result | Fix |\n|---------|--------|-----|\n| Multiple WSS with `server` option | HTTP 400 written to socket | Use `noServer: true` |\n| `perMessageDeflate: true` (default in older ws) | RSV1 set on frames | Explicitly set `perMessageDeflate: false` |\n| Not checking upgrade headers | Miss compression negotiation | Log `sec-websocket-extensions` header |\n| Assuming RSV1 error = compression | Could be raw HTTP | Check if bytes decode as ASCII \"HTTP\" |\n\n## Verification Checklist\n\nAfter fixing, verify:\n- [ ] `RSV1: false` in frame inspection\n- [ ] `Extensions header: NONE` in upgrade response\n- [ ] No `HTTP\u002F1.1` in raw frame data\n- [ ] Messages received match sent payload size\n- [ ] Multiple broadcasts work (test interval sends)\n","# Debugging WebSocket Issues\n\n## Overview\n\nWebSocket \"invalid frame header\" errors often stem from raw HTTP being written to an upgraded socket, not actual frame corruption. The most common cause is multiple `WebSocketServer` instances conflicting on the same HTTP server.\n\n## When to Use\n\n- Error: `Invalid WebSocket frame: RSV1 must be clear`\n- Error: `WS_ERR_UNEXPECTED_RSV_1`\n- Error: `Invalid frame header`\n- WebSocket connects then immediately disconnects with code 1006\n- Server logs success but client receives garbage data\n\n## Quick Reference\n\n| Symptom | Likely Cause | Fix |\n|---------|--------------|-----|\n| RSV1 must be clear | Multiple WSS on same server OR compression mismatch | Use `noServer: true` mode |\n| Hex starts with `48545450` | Raw HTTP on WebSocket (0x48='H') | Check for conflicting upgrade handlers |\n| Code 1006, no reason | Abnormal closure, often server-side abort | Check `abortHandshake` calls |\n| Works isolated, fails in app | Something else writing to socket | Audit all upgrade listeners |\n\n## The Multiple WebSocketServer Bug\n\n### Problem\n\nWhen attaching multiple `WebSocketServer` instances to the same HTTP server using the `server` option:\n\n```typescript\n\u002F\u002F ❌ BAD - Both servers add upgrade listeners, causing conflicts\nconst wss1 = new WebSocketServer({ server, path: '\u002Fws' });\nconst wss2 = new WebSocketServer({ server, path: '\u002Fws\u002Fother' });\n```\n\n**What happens:**\n1. Client connects to `\u002Fws`\n2. BOTH upgrade handlers fire (Node.js EventEmitter calls all listeners)\n3. `wss1` matches path, handles upgrade successfully\n4. `wss2` doesn't match, calls `abortHandshake(socket, 400)`\n5. Raw `HTTP\u002F1.1 400 Bad Request` written to the now-WebSocket socket\n6. Client receives HTTP text as WebSocket frame data\n7. First byte `0x48` ('H') interpreted as: RSV1=1, opcode=8 → invalid frame\n\n### Solution\n\nUse `noServer: true` and manually route upgrades:\n\n```typescript\n\u002F\u002F ✅ GOOD - Single upgrade handler routes to correct server\nconst wss1 = new WebSocketServer({ noServer: true, perMessageDeflate: false });\nconst wss2 = new WebSocketServer({ noServer: true, perMessageDeflate: false });\n\nserver.on('upgrade', (request, socket, head) => {\n  const pathname = new URL(request.url || '', `http:\u002F\u002F${request.headers.host}`).pathname;\n\n  if (pathname === '\u002Fws') {\n    wss1.handleUpgrade(request, socket, head, (ws) => {\n      wss1.emit('connection', ws, request);\n    });\n  } else if (pathname === '\u002Fws\u002Fother') {\n    wss2.handleUpgrade(request, socket, head, (ws) => {\n      wss2.emit('connection', ws, request);\n    });\n  } else {\n    socket.destroy();\n  }\n});\n```\n\n## Debugging Techniques\n\n### Raw Frame Inspection\n\nHook into the socket to see actual bytes received:\n\n```typescript\nws.on('open', () => {\n  const socket = ws._socket;\n  const originalPush = socket.push.bind(socket);\n\n  socket.push = function(chunk, encoding) {\n    if (chunk) {\n      console.log('First 20 bytes (hex):', chunk.slice(0, 20).toString('hex'));\n      const byte0 = chunk[0];\n      console.log(`FIN: ${!!(byte0 & 0x80)}, RSV1: ${!!(byte0 & 0x40)}, Opcode: ${byte0 & 0x0f}`);\n\n      \u002F\u002F Check if it's actually HTTP text\n      if (chunk.slice(0, 4).toString() === 'HTTP') {\n        console.log('*** RECEIVED RAW HTTP ON WEBSOCKET ***');\n      }\n    }\n    return originalPush(chunk, encoding);\n  };\n});\n```\n\n### Key Hex Patterns\n\n- `81` = FIN + text frame (normal)\n- `82` = FIN + binary frame (normal)\n- `88` = FIN + close frame (normal)\n- `48545450` = \"HTTP\" - raw HTTP on WebSocket (bug!)\n- `c1` or similar with bit 6 set = compressed frame (RSV1=1)\n\n## Common Mistakes\n\n| Mistake | Result | Fix |\n|---------|--------|-----|\n| Multiple WSS with `server` option | HTTP 400 written to socket | Use `noServer: true` |\n| `perMessageDeflate: true` (default in older ws) | RSV1 set on frames | Explicitly set `perMessageDeflate: false` |\n| Not checking upgrade headers | Miss compression negotiation | Log `sec-websocket-extensions` header |\n| Assuming RSV1 error = compression | Could be raw HTTP | Check if bytes decode as ASCII \"HTTP\" |\n\n## Verification Checklist\n\nAfter fixing, verify:\n- [ ] `RSV1: false` in frame inspection\n- [ ] `Extensions header: NONE` in upgrade response\n- [ ] No `HTTP\u002F1.1` in raw frame data\n- [ ] Messages received match sent payload size\n- [ ] Multiple broadcasts work (test interval sends)\n",{"name":5,"tags":29,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fagentworkforce\u002Fdebugging-websocket-issues",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":45,"prompt":55,"zipAvailable":56},[46,49,52],{"tool":47,"command":48},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill debugging-websocket-issues",{"tool":50,"command":51},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill debugging-websocket-issues",{"tool":53,"command":54},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill debugging-websocket-issues","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fagentworkforce\u002Fdebugging-websocket-issues\u002FSKILL.md",true,[58],{"path":59,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":62,"sourceHtmlUrl":63},"skill-report.json","REFERENCE","参考文档",9931,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fagentworkforce\u002Fdebugging-websocket-issues\u002Fskill-report.json",[65,74,83,92,98,104],{"skillNo":66,"name":67,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":30},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[71,72,73],"model","model hierarchy","model hierarchy skill",{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":30},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[80,81,82],"MCP","zoom","zoom mcp",{"skillNo":84,"name":85,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":30},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[89,90,91,81],"sdk","zoom apps sdk","apps",{"skillNo":93,"name":94,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":30},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[94],{"skillNo":99,"name":100,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":30},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[100],{"skillNo":105,"name":106,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":30},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[106]]