-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.questionIssues that look for answers.Issues that look for answers.
Description
When handling a on('request', (req, res) => {}) on does not have to add listener for the error events on req and res since any errors will be forwarded to clientError.
However, when doing on('upgrade', (req, socket, head) => {}), socket can emit an error which might be uncaugth. On common way to implement upgrade is:
server.on(`upgrade`, (req, socket, head) => {
handle(req, socket, head, err => {
if (err) {
// socket.on('error', () => {}) Should this really be neccessary?
if (socket.writable && err.statusCode) {
socket.end(Buffer.from(`HTTP/1.1 ${err.statusCode} ${getStatusText(err.statusCode)}\r\n\r\n`, 'ascii'))
} else {
socket.destroy()
}
}
})
})However, the problem with the above is that it might crash the server if the callback is called with an error and either socket.end or socket.destroy is called and an error is emitted afterward. In such a case shouldn't forward the error to clientError automatically for the user?
Metadata
Metadata
Assignees
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.questionIssues that look for answers.Issues that look for answers.