fix(websocket): guard ws.send/close in checkClients against EPIPE#1821
fix(websocket): guard ws.send/close in checkClients against EPIPE#1821
Conversation
Add readyState check and try-catch around ws.send() and ws.close() in WebSocketManager.checkClients() so a broken pipe (EPIPE) no longer propagates as an unhandled exception. When the graceful close fails the socket is terminated instead. The same pattern is applied to the heartbeat-timeout path and the message-handler error response. Fixes ELECTRON-78
Code Review:fix(websocket): guard ws.send/close in checkClients against EPIPE (#1821)变更概述本 PR 修复了 方案评估结论:✅ 方案合理 本 PR 精准定位根因,并复用了该类其他方法( 问题清单🔵 LOW — 新增测试文件存在大量
|
| # | 严重级别 | 文件 | 问题 |
|---|---|---|---|
| 1 | 🔵 LOW | tests/unit/WebSocketManager.test.ts |
大量 no-explicit-any lint 警告 |
| 2 | 🔵 LOW | WebSocketManager.ts:139–149 |
setupMessageHandler 内层 catch 缺少测试 |
结论
✅ 批准合并 — 无阻塞性问题
修复精准有效,与现有防御性模式一致,测试覆盖了关键的 EPIPE 场景,两个 LOW 级问题均不阻塞合并。
本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
Summary
ws.send()andws.close()inWebSocketManager.checkClients()withreadyStatechecks and try-catch to prevent unhandled EPIPE exceptions when the underlying socket pipe is brokenws.terminate()when graceful close failsSentry Issue
Error: write EPIPEinWebSocketManager.checkClients(816 occurrences, ongoing)ws.send()called on a broken socket during token expiry handling without readyState guard or error handlingRoot Cause
checkClients()sends anauth-expiredmessage viaws.send()and then callsws.close()without checkingws.readyStateor wrapping in try-catch. When the client's socket pipe is already broken (common on low-resource Linux machines), this throws an unhandled EPIPE. Other methods likesendHeartbeat()andvalidateConnection()already had similar guards.Test Plan
ws.send()during auth-expired → falls back tows.terminate()ws.close()during heartbeat timeout → falls back tows.terminate()ws.send()whenreadyState !== OPENfor expired tokenbun run testpassesbunx tsc --noEmitpassesbun run lint:fixcleanbun run formatclean