Skip to content

Commit

Permalink
Move timer initialization to the beginning of channel construction
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Sep 17, 2020
1 parent 6a32c00 commit a160081
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/grpc-js/src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export enum ConnectivityState {
SHUTDOWN,
}

/**
* See https://nodejs.org/api/timers.html#timers_setinterval_callback_delay_args
*/
const MAX_TIMEOUT_TIME = 2147483647;

let nextCallNumber = 0;

function getNewCallNumber(): number {
Expand Down Expand Up @@ -185,6 +190,10 @@ export class ChannelImplementation implements Channel {
`Could not find a default scheme for target name "${target}"`
);
}

this.callRefTimer = setInterval(() => {}, MAX_TIMEOUT_TIME);
this.callRefTimer.unref?.();

if (this.options['grpc.default_authority']) {
this.defaultAuthority = this.options['grpc.default_authority'] as string;
} else {
Expand Down Expand Up @@ -239,9 +248,6 @@ export class ChannelImplementation implements Channel {
new MaxMessageSizeFilterFactory(this.options),
new CompressionFilterFactory(this),
]);

this.callRefTimer = setInterval(() => {}, 1 << 31 - 1);
this.callRefTimer.unref?.();
}

private pushPick(callStream: Http2CallStream, callMetadata: Metadata) {
Expand Down

0 comments on commit a160081

Please sign in to comment.