Skip to content

Commit

Permalink
Merge pull request #12959 from yurks/fix-grpc-client-closing
Browse files Browse the repository at this point in the history
fix(microservices): grpc client closing
  • Loading branch information
kamilmysliwiec authored Jan 23, 2024
2 parents 783cf5c + eef4334 commit ec57fba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/microservices/client/client-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,12 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
}

public close() {
this.grpcClients
.filter(client => client && isFunction(client.close))
.forEach(client => client.close());
this.clients.forEach(client => {
if (client && isFunction(client.close)) {
client.close();
}
});
this.clients.clear();
this.grpcClients = [];
}

Expand Down
5 changes: 4 additions & 1 deletion packages/microservices/test/client/client-grpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,13 @@ describe('ClientGrpcProxy', () => {
describe('close', () => {
it('should call "close" method', () => {
const grpcClient = { close: sinon.spy() };
(client as any).grpcClients[0] = grpcClient;
(client as any).clients.set('test', grpcClient);
(client as any).grpcClients[0] = {};

client.close();
expect(grpcClient.close.called).to.be.true;
expect((client as any).clients.size).to.be.eq(0);
expect((client as any).grpcClients.length).to.be.eq(0);
});
});

Expand Down

0 comments on commit ec57fba

Please sign in to comment.