fix: cancel the cleanup task inside the unrefUnusedSubchannels function

This commit is contained in:
Joram 2019-11-06 15:10:19 +01:00
parent 93f8169139
commit 5f271de8c2
2 changed files with 7 additions and 16 deletions

View File

@ -289,7 +289,7 @@ export class ChannelImplementation implements Channel {
this.resolvingLoadBalancer.destroy();
this.updateState(ConnectivityState.SHUTDOWN);
this.subchannelPool.forceCleanup();
this.subchannelPool.unrefUnusedSubchannels();
}
getTarget() {

View File

@ -55,7 +55,7 @@ export class SubchannelPool {
*
* @returns `true` if all subchannels have been unrefed. `false` otherwise.
*/
unrefUnusedSubchannels(): boolean {
unrefUnusedSubchannels(): void {
let allSubchannelsUnrefed = true;
/* These objects are created with Object.create(null), so they do not
@ -85,7 +85,11 @@ export class SubchannelPool {
/* Currently we do not delete keys with empty values. If that results
* in significant memory usage we should change it. */
return allSubchannelsUnrefed;
// Cancel the cleanup task if all subchannels have been unrefed.
if (allSubchannelsUnrefed && this.cleanupTimer !== undefined) {
clearInterval(this.cleanupTimer);
this.cleanupTimer = undefined;
}
}
/**
@ -102,19 +106,6 @@ export class SubchannelPool {
}
}
/**
* Unrefs unused subchannels and cancels the cleanup task if all
* subchannels have been unrefed.
*/
forceCleanup(): void {
const allSubchannelsUnrefed = this.unrefUnusedSubchannels();
if (allSubchannelsUnrefed && this.cleanupTimer !== undefined) {
clearInterval(this.cleanupTimer);
this.cleanupTimer = undefined;
}
}
/**
* Get a subchannel if one already exists with exactly matching parameters.
* Otherwise, create and save a subchannel with those parameters.