1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 04:35:25 +00:00

Close sockets correctly

This commit is contained in:
Asher 2020-11-10 17:52:02 -06:00
parent f706039a9d
commit b8340a2ae9
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 2 additions and 4 deletions

View File

@ -155,7 +155,7 @@ export const register = async (
const wsErrorHandler: express.ErrorRequestHandler = async (err, req) => { const wsErrorHandler: express.ErrorRequestHandler = async (err, req) => {
logger.error(`${err.message} ${err.stack}`) logger.error(`${err.message} ${err.stack}`)
;(req as WebsocketRequest).ws.destroy(err) ;(req as WebsocketRequest).ws.end()
} }
wsApp.use(wsErrorHandler) wsApp.use(wsErrorHandler)

View File

@ -5,8 +5,6 @@ import * as net from "net"
export const handleUpgrade = (app: express.Express, server: http.Server): void => { export const handleUpgrade = (app: express.Express, server: http.Server): void => {
server.on("upgrade", (req, socket, head) => { server.on("upgrade", (req, socket, head) => {
socket.on("error", () => socket.destroy())
req.ws = socket req.ws = socket
req.head = head req.head = head
req._ws_handled = false 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. // Send the request off to be handled by Express.
;(app as any).handle(req, new http.ServerResponse(req), () => { ;(app as any).handle(req, new http.ServerResponse(req), () => {
if (!req._ws_handled) { if (!req._ws_handled) {
socket.destroy(new Error("Not found")) socket.end("HTTP/1.1 404 Not Found\r\n\r\n")
} }
}) })
}) })