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

Function closeStream

lib/internal/http2/core.js:2016–2056  ·  view source on GitHub ↗
(stream, code, rstStreamStatus = kSubmitRstStream)

Source from the content-addressed store, hash-verified

2014const kForceRstStream = 2;
2015
2016function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) {
2017 const type = stream[kSession][kType];
2018 const state = stream[kState];
2019 state.flags |= STREAM_FLAGS_CLOSED;
2020 state.rstCode = code;
2021
2022 // Clear timeout and remove timeout listeners
2023 stream.setTimeout(0);
2024 stream.removeAllListeners('timeout');
2025
2026 const { ending } = stream._writableState;
2027
2028 if (!ending) {
2029 // If the writable side of the Http2Stream is still open, emit the
2030 // 'aborted' event and set the aborted flag.
2031 if (!stream.aborted) {
2032 state.flags |= STREAM_FLAGS_ABORTED;
2033 stream.emit('aborted');
2034 }
2035
2036 // Close the writable side.
2037 stream.end();
2038 }
2039
2040 if (rstStreamStatus !== kNoRstStream) {
2041 const finishFn = finishCloseStream.bind(stream, code);
2042 if (!ending || stream.writableFinished || code !== NGHTTP2_NO_ERROR ||
2043 rstStreamStatus === kForceRstStream)
2044 finishFn();
2045 else
2046 stream.once('finish', finishFn);
2047 }
2048
2049 if (type === NGHTTP2_SESSION_CLIENT) {
2050 if (onClientStreamCloseChannel.hasSubscribers) {
2051 onClientStreamCloseChannel.publish({ stream });
2052 }
2053 } else if (onServerStreamCloseChannel.hasSubscribers) {
2054 onServerStreamCloseChannel.publish({ stream });
2055 }
2056}
2057
2058function finishCloseStream(code) {
2059 const rstStreamFn = submitRstStream.bind(this, code);

Callers 3

onStreamCloseFunction · 0.85
closeMethod · 0.85
_destroyMethod · 0.85

Calls 7

setTimeoutMethod · 0.45
removeAllListenersMethod · 0.45
emitMethod · 0.45
endMethod · 0.45
bindMethod · 0.45
onceMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…