Skip to content

Commit a160081

Browse files
committed
Move timer initialization to the beginning of channel construction
1 parent 6a32c00 commit a160081

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/grpc-js/src/channel.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export enum ConnectivityState {
4848
SHUTDOWN,
4949
}
5050

51+
/**
52+
* See https://nodejs.org/api/timers.html#timers_setinterval_callback_delay_args
53+
*/
54+
const MAX_TIMEOUT_TIME = 2147483647;
55+
5156
let nextCallNumber = 0;
5257

5358
function getNewCallNumber(): number {
@@ -185,6 +190,10 @@ export class ChannelImplementation implements Channel {
185190
`Could not find a default scheme for target name "${target}"`
186191
);
187192
}
193+
194+
this.callRefTimer = setInterval(() => {}, MAX_TIMEOUT_TIME);
195+
this.callRefTimer.unref?.();
196+
188197
if (this.options['grpc.default_authority']) {
189198
this.defaultAuthority = this.options['grpc.default_authority'] as string;
190199
} else {
@@ -239,9 +248,6 @@ export class ChannelImplementation implements Channel {
239248
new MaxMessageSizeFilterFactory(this.options),
240249
new CompressionFilterFactory(this),
241250
]);
242-
243-
this.callRefTimer = setInterval(() => {}, 1 << 31 - 1);
244-
this.callRefTimer.unref?.();
245251
}
246252

247253
private pushPick(callStream: Http2CallStream, callMetadata: Metadata) {

0 commit comments

Comments
 (0)