From ba62be40b4f46c98872fb10990b559fee88f4a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=B7=8D=E5=B3=B0?= Date: Thu, 25 Aug 2022 02:16:46 +0800 Subject: [PATCH] fix: close socket when client error handled (#9816) --- packages/vite/src/node/http.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index 331781425..86fa79207 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -190,7 +190,9 @@ export function setClientErrorHandler( logger: Logger ): void { server.on('clientError', (err, socket) => { + let msg = '400 Bad Request' if ((err as any).code === 'HPE_HEADER_OVERFLOW') { + msg = '431 Request Header Fields Too Large' logger.warn( colors.yellow( 'Server responded with status code 431. ' + @@ -198,5 +200,9 @@ export function setClientErrorHandler( ) ) } + if ((err as any).code === 'ECONNRESET' || !socket.writable) { + return + } + socket.end(`HTTP/1.1 ${msg}\r\n\r\n`) }) }