grpc-js: Ref and unref backoff timer

This commit is contained in:
Michael Lumish 2021-02-11 09:55:24 -08:00
parent b5a8ea10f8
commit cd14345cb4
6 changed files with 23 additions and 4 deletions

View File

@ -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": {
@ -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"

View File

@ -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]) => {

View File

@ -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",

View File

@ -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) {
@ -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
@ -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();
}
}

View File

@ -196,6 +196,7 @@ export class ResolvingLoadBalancer implements LoadBalancer {
this.updateState(this.latestChildState, this.latestChildPicker);
}
});
this.backoffTimeout.unref();
}
private updateResolution() {

View File

@ -615,6 +615,7 @@ export class Subchannel {
if (this.session) {
this.session.ref();
}
this.backoffTimeout.ref();
if (!this.keepaliveWithoutCalls) {
this.startKeepalivePings();
}
@ -635,6 +636,7 @@ export class Subchannel {
if (this.session) {
this.session.unref();
}
this.backoffTimeout.unref();
if (!this.keepaliveWithoutCalls) {
this.stopKeepalivePings();
}