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",
|
"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.",
|
"description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.",
|
||||||
"main": "build/src/index.js",
|
"main": "build/src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
"@grpc/proto-loader": "^0.6.0-pre14"
|
"@grpc/proto-loader": "^0.6.0-pre14"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@grpc/grpc-js": "~1.2.2"
|
"@grpc/grpc-js": "~1.2.7"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.10.0"
|
"node": ">=10.10.0"
|
||||||
|
|
|
@ -774,9 +774,11 @@ export class XdsClient {
|
||||||
this.adsBackoff = new BackoffTimeout(() => {
|
this.adsBackoff = new BackoffTimeout(() => {
|
||||||
this.maybeStartAdsStream();
|
this.maybeStartAdsStream();
|
||||||
});
|
});
|
||||||
|
this.adsBackoff.unref();
|
||||||
this.lrsBackoff = new BackoffTimeout(() => {
|
this.lrsBackoff = new BackoffTimeout(() => {
|
||||||
this.maybeStartLrsStream();
|
this.maybeStartLrsStream();
|
||||||
})
|
});
|
||||||
|
this.lrsBackoff.unref();
|
||||||
|
|
||||||
Promise.all([loadBootstrapInfo(), loadAdsProtos()]).then(
|
Promise.all([loadBootstrapInfo(), loadAdsProtos()]).then(
|
||||||
([bootstrapInfo, protoDefinitions]) => {
|
([bootstrapInfo, protoDefinitions]) => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@grpc/grpc-js",
|
"name": "@grpc/grpc-js",
|
||||||
"version": "1.2.6",
|
"version": "1.2.7",
|
||||||
"description": "gRPC Library for Node - pure JS implementation",
|
"description": "gRPC Library for Node - pure JS implementation",
|
||||||
"homepage": "https://grpc.io/",
|
"homepage": "https://grpc.io/",
|
||||||
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
|
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
|
||||||
|
|
|
@ -44,6 +44,7 @@ export class BackoffTimeout {
|
||||||
private nextDelay: number;
|
private nextDelay: number;
|
||||||
private timerId: NodeJS.Timer;
|
private timerId: NodeJS.Timer;
|
||||||
private running = false;
|
private running = false;
|
||||||
|
private hasRef = true;
|
||||||
|
|
||||||
constructor(private callback: () => void, options?: BackoffOptions) {
|
constructor(private callback: () => void, options?: BackoffOptions) {
|
||||||
if (options) {
|
if (options) {
|
||||||
|
@ -74,6 +75,9 @@ export class BackoffTimeout {
|
||||||
this.callback();
|
this.callback();
|
||||||
this.running = false;
|
this.running = false;
|
||||||
}, this.nextDelay);
|
}, this.nextDelay);
|
||||||
|
if (!this.hasRef) {
|
||||||
|
this.timerId.unref();
|
||||||
|
}
|
||||||
const nextBackoff = Math.min(
|
const nextBackoff = Math.min(
|
||||||
this.nextDelay * this.multiplier,
|
this.nextDelay * this.multiplier,
|
||||||
this.maxDelay
|
this.maxDelay
|
||||||
|
@ -102,4 +106,14 @@ export class BackoffTimeout {
|
||||||
isRunning() {
|
isRunning() {
|
||||||
return this.running;
|
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.updateState(this.latestChildState, this.latestChildPicker);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.backoffTimeout.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateResolution() {
|
private updateResolution() {
|
||||||
|
|
|
@ -615,6 +615,7 @@ export class Subchannel {
|
||||||
if (this.session) {
|
if (this.session) {
|
||||||
this.session.ref();
|
this.session.ref();
|
||||||
}
|
}
|
||||||
|
this.backoffTimeout.ref();
|
||||||
if (!this.keepaliveWithoutCalls) {
|
if (!this.keepaliveWithoutCalls) {
|
||||||
this.startKeepalivePings();
|
this.startKeepalivePings();
|
||||||
}
|
}
|
||||||
|
@ -635,6 +636,7 @@ export class Subchannel {
|
||||||
if (this.session) {
|
if (this.session) {
|
||||||
this.session.unref();
|
this.session.unref();
|
||||||
}
|
}
|
||||||
|
this.backoffTimeout.unref();
|
||||||
if (!this.keepaliveWithoutCalls) {
|
if (!this.keepaliveWithoutCalls) {
|
||||||
this.stopKeepalivePings();
|
this.stopKeepalivePings();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue