mirror of https://github.com/grpc/grpc-node.git
grpc-js: Ref and unref backoff timer
This commit is contained in:
parent
b5a8ea10f8
commit
cd14345cb4
|
@ -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"
|
||||
|
|
|
@ -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]) => {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,6 +196,7 @@ export class ResolvingLoadBalancer implements LoadBalancer {
|
|||
this.updateState(this.latestChildState, this.latestChildPicker);
|
||||
}
|
||||
});
|
||||
this.backoffTimeout.unref();
|
||||
}
|
||||
|
||||
private updateResolution() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue