MCPcopy Index your code
hub / github.com/nodejs/node / _destroy

Method _destroy

lib/internal/http2/core.js:2444–2523  ·  view source on GitHub ↗
(err, callback)

Source from the content-addressed store, hash-verified

2442 // This will cause the internal resources to be released.
2443 // * Then cleans up the resources on the js side
2444 _destroy(err, callback) {
2445 const session = this[kSession];
2446 const handle = this[kHandle];
2447 const id = this[kID];
2448
2449 debugStream(this[kID] || 'pending', session[kType], 'destroying stream');
2450
2451 const state = this[kState];
2452 const sessionState = session[kState];
2453 const sessionCode = sessionState.goawayCode || sessionState.destroyCode;
2454
2455 // If a stream has already closed successfully, there is no error
2456 // to report from this stream, even if the session has errored.
2457 // This can happen if the stream was already in process of destroying
2458 // after a successful close, but the session had a error between
2459 // this stream's close and destroy operations.
2460 // Previously, this always overrode a successful close operation code
2461 // NGHTTP2_NO_ERROR (0) with sessionCode because the use of the || operator.
2462 let code = this.closed ? this.rstCode : sessionCode;
2463 if (err != null) {
2464 if (sessionCode) {
2465 code = sessionCode;
2466 } else if (err instanceof AbortError) {
2467 // Enables using AbortController to cancel requests with RST code 8.
2468 code = NGHTTP2_CANCEL;
2469 } else {
2470 code = NGHTTP2_INTERNAL_ERROR;
2471 }
2472 }
2473 const hasHandle = handle !== undefined;
2474
2475 if (!this.closed)
2476 closeStream(this, code, hasHandle ? kForceRstStream : kNoRstStream);
2477 this.push(null);
2478
2479 if (hasHandle) {
2480 handle.destroy();
2481 sessionState.streams.delete(id);
2482 } else {
2483 sessionState.pendingStreams.delete(this);
2484 }
2485
2486 // Adjust the write queue size for accounting
2487 sessionState.writeQueueSize -= state.writeQueueSize;
2488 state.writeQueueSize = 0;
2489
2490 // RST code 8 not emitted as an error as its used by clients to signify
2491 // abort and is already covered by aborted event, also allows more
2492 // seamless compatibility with http1
2493 if (err == null && code !== NGHTTP2_NO_ERROR && code !== NGHTTP2_CANCEL)
2494 err = new ERR_HTTP2_STREAM_ERROR(nameForErrorCode[code] || code);
2495
2496 this[kSession] = undefined;
2497 this[kHandle] = undefined;
2498
2499 // This notifies the session that this stream has been destroyed and
2500 // gives the session the opportunity to clean itself up. The session
2501 // will destroy if it has been closed and there are no other open or

Callers

nothing calls this directly

Calls 8

debugStreamFunction · 0.85
closeStreamFunction · 0.85
deleteMethod · 0.65
setImmediateFunction · 0.50
callbackFunction · 0.50
pushMethod · 0.45
destroyMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected