Skip to content

Commit 51d6163

Browse files
authored
Merge pull request #2519 from murgatroid99/grpc-js_keepalive_order_fix
grpc-js: Fix a crash when `grpc.keepalive_permit_without_calls` is set
2 parents 18dacfa + 6d97956 commit 51d6163

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.8.19",
3+
"version": "1.8.20",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

packages/grpc-js/src/transport.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ class Http2Transport implements Transport {
126126
*/
127127
private remoteName: string | null
128128
) {
129+
/* Populate subchannelAddressString and channelzRef before doing anything
130+
* else, because they are used in the trace methods. */
131+
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
132+
133+
if (options['grpc.enable_channelz'] === 0) {
134+
this.channelzEnabled = false;
135+
}
136+
this.channelzRef = registerChannelzSocket(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled);
129137
// Build user-agent string.
130138
this.userAgent = [
131139
options['grpc.primary_user_agent'],
@@ -147,16 +155,6 @@ class Http2Transport implements Transport {
147155
} else {
148156
this.keepaliveWithoutCalls = false;
149157
}
150-
if (this.keepaliveWithoutCalls) {
151-
this.maybeStartKeepalivePingTimer();
152-
}
153-
154-
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
155-
156-
if (options['grpc.enable_channelz'] === 0) {
157-
this.channelzEnabled = false;
158-
}
159-
this.channelzRef = registerChannelzSocket(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled);
160158

161159
session.once('close', () => {
162160
this.trace('session closed');
@@ -205,6 +203,11 @@ class Http2Transport implements Transport {
205203
);
206204
});
207205
}
206+
/* Start the keepalive timer last, because this can trigger trace logs,
207+
* which should only happen after everything else is set up. */
208+
if (this.keepaliveWithoutCalls) {
209+
this.maybeStartKeepalivePingTimer();
210+
}
208211
}
209212

210213
private getChannelzInfo(): SocketInfo {

0 commit comments

Comments
 (0)