Merge pull request #2519 from murgatroid99/grpc-js_keepalive_order_fix

grpc-js: Fix a crash when `grpc.keepalive_permit_without_calls` is set
This commit is contained in:
Michael Lumish 2023-07-25 10:03:32 -07:00 committed by GitHub
commit 51d6163eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.8.19",
"version": "1.8.20",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

View File

@ -126,6 +126,14 @@ class Http2Transport implements Transport {
*/
private remoteName: string | null
) {
/* Populate subchannelAddressString and channelzRef before doing anything
* else, because they are used in the trace methods. */
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
if (options['grpc.enable_channelz'] === 0) {
this.channelzEnabled = false;
}
this.channelzRef = registerChannelzSocket(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled);
// Build user-agent string.
this.userAgent = [
options['grpc.primary_user_agent'],
@ -147,16 +155,6 @@ class Http2Transport implements Transport {
} else {
this.keepaliveWithoutCalls = false;
}
if (this.keepaliveWithoutCalls) {
this.maybeStartKeepalivePingTimer();
}
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
if (options['grpc.enable_channelz'] === 0) {
this.channelzEnabled = false;
}
this.channelzRef = registerChannelzSocket(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled);
session.once('close', () => {
this.trace('session closed');
@ -205,6 +203,11 @@ class Http2Transport implements Transport {
);
});
}
/* Start the keepalive timer last, because this can trigger trace logs,
* which should only happen after everything else is set up. */
if (this.keepaliveWithoutCalls) {
this.maybeStartKeepalivePingTimer();
}
}
private getChannelzInfo(): SocketInfo {