diff --git a/packages/microservices/client/client-grpc.ts b/packages/microservices/client/client-grpc.ts index 733b8d1d674..d567f253b5d 100644 --- a/packages/microservices/client/client-grpc.ts +++ b/packages/microservices/client/client-grpc.ts @@ -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 = []; } diff --git a/packages/microservices/test/client/client-grpc.spec.ts b/packages/microservices/test/client/client-grpc.spec.ts index c3a98796101..a6fb314be12 100644 --- a/packages/microservices/test/client/client-grpc.spec.ts +++ b/packages/microservices/test/client/client-grpc.spec.ts @@ -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); }); });