Skip to content

Commit 53bc5c8

Browse files
bartlomiejuclaude
andcommitted
fix: handle broken pipe errors and fix Buffer type in WS proxy
- Replace Buffer type with Uint8Array to fix CI type checking - Add onError handler to Deno.serve to suppress broken pipe errors - Add close event handlers on proxy sockets for clean teardown - Wrap destroy calls in try/catch to prevent cascading errors Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ac26e1 commit 53bc5c8

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

packages/plugin-vite/src/plugins/dev_server.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export function devServer(): Plugin[] {
2424
// where Deno.upgradeWebSocket() works natively.
2525
let wsPort = 0;
2626
const wsServer = Deno.serve(
27-
{ port: 0, onListen: ({ port }) => wsPort = port },
27+
{
28+
port: 0,
29+
onListen: ({ port }) => wsPort = port,
30+
onError: () =>
31+
new Response("Internal Server Error", { status: 500 }),
32+
},
2833
async (req) => {
2934
try {
3035
const mod = await server.ssrLoadModule("fresh:server_entry");
@@ -51,7 +56,7 @@ export function devServer(): Plugin[] {
5156
rawHeaders: string[];
5257
},
5358
clientSocket: import("node:net").Socket,
54-
head: Buffer,
59+
head: Uint8Array,
5560
) => {
5661
// Let Vite handle its own HMR WebSocket upgrades
5762
if (
@@ -76,8 +81,18 @@ export function devServer(): Plugin[] {
7681
proxySocket.pipe(clientSocket);
7782
});
7883

79-
proxySocket.on("error", () => clientSocket.destroy());
80-
clientSocket.on("error", () => proxySocket.destroy());
84+
proxySocket.on("error", () => {
85+
try {
86+
clientSocket.destroy();
87+
} catch { /* ignore */ }
88+
});
89+
clientSocket.on("error", () => {
90+
try {
91+
proxySocket.destroy();
92+
} catch { /* ignore */ }
93+
});
94+
clientSocket.on("close", () => proxySocket.destroy());
95+
proxySocket.on("close", () => clientSocket.destroy());
8196
},
8297
);
8398

0 commit comments

Comments
 (0)