(
request: http.IncomingMessage,
socket: stream.Duplex,
head: Buffer,
)
| 390 | } |
| 391 | |
| 392 | protected async handleWebSocket( |
| 393 | request: http.IncomingMessage, |
| 394 | socket: stream.Duplex, |
| 395 | head: Buffer, |
| 396 | ) { |
| 397 | const req = request as Request; |
| 398 | |
| 399 | // A client resetting the connection mid-handshake emits 'error' on the |
| 400 | // raw socket; with no listener that's an uncaught exception that kills |
| 401 | // the process. |
| 402 | socket.on('error', (err) => { |
| 403 | this.logger.error(`WebSocket socket error: ${err.message}`); |
| 404 | }); |
| 405 | |
| 406 | // Same rationale as handleRequest: a throw here is an unhandled |
| 407 | // rejection on the 'upgrade' listener and crashes the process. |
| 408 | try { |
| 409 | await this.handleWebSocketUnsafe(req, socket, head); |
| 410 | } catch (e: unknown) { |
| 411 | this.handleErrorRequest(e as Error, socket, req); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | protected async handleWebSocketUnsafe( |
| 416 | req: Request, |
no test coverage detected