MCPcopy Create free account
hub / github.com/nodejs/node / failWebsocketConnection

Function failWebsocketConnection

deps/undici/src/lib/web/websocket/connection.js:306–323  ·  view source on GitHub ↗

* @param {import('./websocket').Handler} handler * @param {number} code * @param {string|undefined} reason * @param {unknown} cause * @returns {void}

(handler, code, reason, cause)

Source from the content-addressed store, hash-verified

304 * @returns {void}
305 */
306function failWebsocketConnection (handler, code, reason, cause) {
307 // If _The WebSocket Connection is Established_ prior to the point where
308 // the endpoint is required to _Fail the WebSocket Connection_, the
309 // endpoint SHOULD send a Close frame with an appropriate status code
310 // (Section 7.4) before proceeding to _Close the WebSocket Connection_.
311 if (isEstablished(handler.readyState)) {
312 closeWebSocketConnection(handler, code, reason, false)
313 }
314
315 handler.controller.abort()
316
317 if (isConnecting(handler.readyState)) {
318 // If the connection was not established, we must still emit an 'error' and 'close' events
319 handler.onSocketClose()
320 } else if (handler.socket?.destroyed === false) {
321 handler.socket.destroy()
322 }
323}
324
325module.exports = {
326 establishWebSocketConnection,

Callers 11

runMethod · 0.70
writeFragmentsMethod · 0.70
parseControlFrameMethod · 0.70
processResponseFunction · 0.70
closeWebSocketConnectionFunction · 0.70
WebSocketClass · 0.70
#onMessageMethod · 0.70
WebSocketStreamClass · 0.50
constructorMethod · 0.50
#onMessageMethod · 0.50

Calls 5

isEstablishedFunction · 0.70
closeWebSocketConnectionFunction · 0.70
isConnectingFunction · 0.70
abortMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected