Skip to content

Commit ec57fba

Browse files
authoredJan 23, 2024
Merge pull request #12959 from yurks/fix-grpc-client-closing
fix(microservices): grpc client closing
2 parents 783cf5c + eef4334 commit ec57fba

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

‎packages/microservices/client/client-grpc.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,12 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
330330
}
331331

332332
public close() {
333-
this.grpcClients
334-
.filter(client => client && isFunction(client.close))
335-
.forEach(client => client.close());
333+
this.clients.forEach(client => {
334+
if (client && isFunction(client.close)) {
335+
client.close();
336+
}
337+
});
338+
this.clients.clear();
336339
this.grpcClients = [];
337340
}
338341

‎packages/microservices/test/client/client-grpc.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,13 @@ describe('ClientGrpcProxy', () => {
462462
describe('close', () => {
463463
it('should call "close" method', () => {
464464
const grpcClient = { close: sinon.spy() };
465-
(client as any).grpcClients[0] = grpcClient;
465+
(client as any).clients.set('test', grpcClient);
466+
(client as any).grpcClients[0] = {};
466467

467468
client.close();
468469
expect(grpcClient.close.called).to.be.true;
470+
expect((client as any).clients.size).to.be.eq(0);
471+
expect((client as any).grpcClients.length).to.be.eq(0);
469472
});
470473
});
471474

0 commit comments

Comments
 (0)
Please sign in to comment.