mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 21:32:05 +00:00
### What does this PR do? The `sendPong` fix alone wasn't sufficient. The bug only manifests with **wss:// through HTTP proxy** (not ws://), because only that path uses `initWithTunnel` with a detached socket. **Two bugs were found and fixed:** 1. **`sendPong`/`sendCloseWithBody` socket checks** (`src/http/websocket_client.zig`): Replaced `socket.isClosed() or socket.isShutdown()` with `!this.hasTCP()` as originally proposed. Also guarded `shutdownRead()` against detached sockets. 2. **Spurious 1006 during clean close** (`src/http/websocket_client.zig` + `WebSocketProxyTunnel.zig`): When `sendCloseWithBody` calls `clearData()`, it shuts down the proxy tunnel. The tunnel's `onClose` callback was calling `ws.fail(ErrorCode.ended)` which dispatched a 1006 abrupt close, overriding the clean 1000 close already in progress. Fixed by adding `tunnel.clearConnectedWebSocket()` before `tunnel.shutdown()` so the callback is a no-op. ### How did you verify your code works? - `USE_SYSTEM_BUN=1`: Fails with `Unexpected close code: 1006` - `bun bd test`: Passes with clean 1000 close - Full proxy test suite: 25 pass, 4 skip, 0 fail - Related fragmented/close tests: all passing --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com>