Close sockets correctly
This commit is contained in:
parent
f706039a9d
commit
b8340a2ae9
@ -155,7 +155,7 @@ export const register = async (
|
||||
|
||||
const wsErrorHandler: express.ErrorRequestHandler = async (err, req) => {
|
||||
logger.error(`${err.message} ${err.stack}`)
|
||||
;(req as WebsocketRequest).ws.destroy(err)
|
||||
;(req as WebsocketRequest).ws.end()
|
||||
}
|
||||
|
||||
wsApp.use(wsErrorHandler)
|
||||
|
@ -5,8 +5,6 @@ import * as net from "net"
|
||||
|
||||
export const handleUpgrade = (app: express.Express, server: http.Server): void => {
|
||||
server.on("upgrade", (req, socket, head) => {
|
||||
socket.on("error", () => socket.destroy())
|
||||
|
||||
req.ws = socket
|
||||
req.head = head
|
||||
req._ws_handled = false
|
||||
@ -14,7 +12,7 @@ export const handleUpgrade = (app: express.Express, server: http.Server): void =
|
||||
// Send the request off to be handled by Express.
|
||||
;(app as any).handle(req, new http.ServerResponse(req), () => {
|
||||
if (!req._ws_handled) {
|
||||
socket.destroy(new Error("Not found"))
|
||||
socket.end("HTTP/1.1 404 Not Found\r\n\r\n")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user