Skip to content

Commit

Permalink
Merge pull request #2103 from murgatroid99/grpc-js_refcounts
Browse files Browse the repository at this point in the history
grpc-js: Fix shutting down subchannels in separate pools
  • Loading branch information
murgatroid99 committed Apr 20, 2022
2 parents 0a9cf38 + 3251422 commit 879d13b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.6.6",
"version": "1.6.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",
Expand Down
14 changes: 5 additions & 9 deletions packages/grpc-js/src/subchannel-pool.ts
Expand Up @@ -49,10 +49,8 @@ export class SubchannelPool {
/**
* A pool of subchannels use for making connections. Subchannels with the
* exact same parameters will be reused.
* @param global If true, this is the global subchannel pool. Otherwise, it
* is the pool for a single channel.
*/
constructor(private global: boolean) {}
constructor() {}

/**
* Unrefs all unused subchannels and cancels the cleanup task if all
Expand Down Expand Up @@ -95,7 +93,7 @@ export class SubchannelPool {
* Ensures that the cleanup task is spawned.
*/
ensureCleanupTask(): void {
if (this.global && this.cleanupTimer === null) {
if (this.cleanupTimer === null) {
this.cleanupTimer = setInterval(() => {
this.unrefUnusedSubchannels();
}, REF_CHECK_INTERVAL);
Expand Down Expand Up @@ -156,14 +154,12 @@ export class SubchannelPool {
channelCredentials,
subchannel,
});
if (this.global) {
subchannel.ref();
}
subchannel.ref();
return subchannel;
}
}

const globalSubchannelPool = new SubchannelPool(true);
const globalSubchannelPool = new SubchannelPool();

/**
* Get either the global subchannel pool, or a new subchannel pool.
Expand All @@ -173,6 +169,6 @@ export function getSubchannelPool(global: boolean): SubchannelPool {
if (global) {
return globalSubchannelPool;
} else {
return new SubchannelPool(false);
return new SubchannelPool();
}
}
2 changes: 1 addition & 1 deletion packages/grpc-js/src/subchannel.ts
Expand Up @@ -741,7 +741,7 @@ export class Subchannel {
}
this.transitionToState(
[ConnectivityState.CONNECTING, ConnectivityState.READY],
ConnectivityState.TRANSIENT_FAILURE
ConnectivityState.IDLE
);
if (this.channelzEnabled) {
unregisterChannelzRef(this.channelzRef);
Expand Down

0 comments on commit 879d13b

Please sign in to comment.