Skip to content

http2: add diagnostics_channel for client session and streams #57955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
const tls = require('tls');
const { setImmediate, setTimeout, clearTimeout } = require('timers');

const dc = require('diagnostics_channel');
const onClientSessionCreatedChannel = dc.channel('http2.client.session.created');
const onClientSessionFinishChannel = dc.channel('http2.client.session.finish');
const onClientStreamCreatedChannel = dc.channel('http2.client.stream.created');
const onClientStreamFinishChannel = dc.channel('http2.client.stream.finish');

const {
kIncomingMessage,
_checkIsHttpToken: checkIsHttpToken,
Expand Down Expand Up @@ -1183,6 +1189,12 @@
state.flags |= SESSION_FLAGS_DESTROYED;
state.destroyCode = code;

if (session instanceof ClientHttp2Session && onClientSessionFinishChannel.hasSubscribers) {

Check failure on line 1192 in lib/internal/http2/core.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'ClientHttp2Session' was used before it was defined
onClientSessionFinishChannel.publish({
session: session,
});
}

// Clear timeout and remove timeout listeners.
session.setTimeout(0);
session.removeAllListeners('timeout');
Expand Down Expand Up @@ -1872,6 +1884,13 @@
} else {
onConnect();
}

if (onClientStreamCreatedChannel.hasSubscribers) {
onClientStreamCreatedChannel.publish({
stream: stream,
});
}

return stream;
}
}
Expand Down Expand Up @@ -1968,6 +1987,12 @@
stream.end();
}

if (stream instanceof ClientHttp2Stream && onClientStreamFinishChannel.hasSubscribers) {

Check failure on line 1990 in lib/internal/http2/core.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'ClientHttp2Stream' was used before it was defined
onClientStreamFinishChannel.publish({
stream: stream,
});
}

if (rstStreamStatus !== kNoRstStream) {
const finishFn = finishCloseStream.bind(stream, code);
if (!ending || stream.writableFinished || code !== NGHTTP2_NO_ERROR ||
Expand Down Expand Up @@ -3399,6 +3424,12 @@
if (typeof listener === 'function')
session.once('connect', listener);

if (onClientSessionCreatedChannel.hasSubscribers) {
onClientSessionCreatedChannel.publish({
session: session,
});
}

return session;
}

Expand Down
Loading