Skip to content

Commit b8340a2

Browse files
committed
Close sockets correctly
1 parent f706039 commit b8340a2

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/node/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const register = async (
155155

156156
const wsErrorHandler: express.ErrorRequestHandler = async (err, req) => {
157157
logger.error(`${err.message} ${err.stack}`)
158-
;(req as WebsocketRequest).ws.destroy(err)
158+
;(req as WebsocketRequest).ws.end()
159159
}
160160

161161
wsApp.use(wsErrorHandler)

src/node/wsRouter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import * as net from "net"
55

66
export const handleUpgrade = (app: express.Express, server: http.Server): void => {
77
server.on("upgrade", (req, socket, head) => {
8-
socket.on("error", () => socket.destroy())
9-
108
req.ws = socket
119
req.head = head
1210
req._ws_handled = false
1311

1412
// Send the request off to be handled by Express.
1513
;(app as any).handle(req, new http.ServerResponse(req), () => {
1614
if (!req._ws_handled) {
17-
socket.destroy(new Error("Not found"))
15+
socket.end("HTTP/1.1 404 Not Found\r\n\r\n")
1816
}
1917
})
2018
})

0 commit comments

Comments
 (0)