Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-js: Ref and unref backoff timer #1688

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/grpc-js-xds/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js-xds",
"version": "1.2.1",
"version": "1.2.2",
"description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.",
"main": "build/src/index.js",
"scripts": {
Expand Down Expand Up @@ -45,7 +45,7 @@
"@grpc/proto-loader": "^0.6.0-pre14"
},
"peerDependencies": {
"@grpc/grpc-js": "~1.2.2"
"@grpc/grpc-js": "~1.2.7"
},
"engines": {
"node": ">=10.10.0"
Expand Down
4 changes: 3 additions & 1 deletion packages/grpc-js-xds/src/xds-client.ts
Expand Up @@ -774,9 +774,11 @@ export class XdsClient {
this.adsBackoff = new BackoffTimeout(() => {
this.maybeStartAdsStream();
});
this.adsBackoff.unref();
this.lrsBackoff = new BackoffTimeout(() => {
this.maybeStartLrsStream();
})
});
this.lrsBackoff.unref();

Promise.all([loadBootstrapInfo(), loadAdsProtos()]).then(
([bootstrapInfo, protoDefinitions]) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.2.6",
"version": "1.2.7",
"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
14 changes: 14 additions & 0 deletions packages/grpc-js/src/backoff-timeout.ts
Expand Up @@ -44,6 +44,7 @@ export class BackoffTimeout {
private nextDelay: number;
private timerId: NodeJS.Timer;
private running = false;
private hasRef = true;

constructor(private callback: () => void, options?: BackoffOptions) {
if (options) {
Expand Down Expand Up @@ -74,6 +75,9 @@ export class BackoffTimeout {
this.callback();
this.running = false;
}, this.nextDelay);
if (!this.hasRef) {
this.timerId.unref();
}
const nextBackoff = Math.min(
this.nextDelay * this.multiplier,
this.maxDelay
Expand Down Expand Up @@ -102,4 +106,14 @@ export class BackoffTimeout {
isRunning() {
return this.running;
}

ref() {
this.hasRef = true;
this.timerId.ref();
}

unref() {
this.hasRef = false;
this.timerId.unref();
}
}
1 change: 1 addition & 0 deletions packages/grpc-js/src/resolving-load-balancer.ts
Expand Up @@ -196,6 +196,7 @@ export class ResolvingLoadBalancer implements LoadBalancer {
this.updateState(this.latestChildState, this.latestChildPicker);
}
});
this.backoffTimeout.unref();
}

private updateResolution() {
Expand Down
2 changes: 2 additions & 0 deletions packages/grpc-js/src/subchannel.ts
Expand Up @@ -615,6 +615,7 @@ export class Subchannel {
if (this.session) {
this.session.ref();
}
this.backoffTimeout.ref();
if (!this.keepaliveWithoutCalls) {
this.startKeepalivePings();
}
Expand All @@ -635,6 +636,7 @@ export class Subchannel {
if (this.session) {
this.session.unref();
}
this.backoffTimeout.unref();
if (!this.keepaliveWithoutCalls) {
this.stopKeepalivePings();
}
Expand Down