From b8340a2ae9f9a543fe3a34c00e51fe925bf20ecd Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 10 Nov 2020 17:52:02 -0600 Subject: [PATCH] Close sockets correctly --- src/node/routes/index.ts | 2 +- src/node/wsRouter.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 4d92c365f..2c54917da 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -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) diff --git a/src/node/wsRouter.ts b/src/node/wsRouter.ts index 1a057f0fa..175f214a8 100644 --- a/src/node/wsRouter.ts +++ b/src/node/wsRouter.ts @@ -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") } }) })