Skip to content

Commit

Permalink
fix: cancel the cleanup task inside the unrefUnusedSubchannels function
Browse files Browse the repository at this point in the history
  • Loading branch information
JrSchild committed Nov 6, 2019
1 parent 93f8169 commit 5f271de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class ChannelImplementation implements Channel {
this.resolvingLoadBalancer.destroy();
this.updateState(ConnectivityState.SHUTDOWN);

this.subchannelPool.forceCleanup();
this.subchannelPool.unrefUnusedSubchannels();
}

getTarget() {
Expand Down
21 changes: 6 additions & 15 deletions packages/grpc-js/src/subchannel-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

/**
Expand All @@ -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.
Expand Down

0 comments on commit 5f271de

Please sign in to comment.