Skip to content

Commit

Permalink
Merge pull request #2519 from murgatroid99/grpc-js_keepalive_order_fix
Browse files Browse the repository at this point in the history
grpc-js: Fix a crash when `grpc.keepalive_permit_without_calls` is set
  • Loading branch information
murgatroid99 committed Jul 25, 2023
2 parents 18dacfa + 6d97956 commit 51d6163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 13 additions & 10 deletions packages/grpc-js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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');
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 51d6163

Please sign in to comment.