Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close socket when client error handled #9816

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/vite/src/node/http.ts
Expand Up @@ -190,13 +190,19 @@ 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. ' +
'See https://vitejs.dev/guide/troubleshooting.html#_431-request-header-fields-too-large.'
)
)
}
if ((err as any).code === 'ECONNRESET' || !socket.writable) {
return
}
socket.end(`HTTP/1.1 ${msg}\r\n\r\n`)
})
}