Skip to content

Commit a9a4eb4

Browse files
Merge pull request #15062 from yatin166/fix/close-redis-and-amqp-client-connection-properly
fix(microservices): ensure all redis and amqp client closes properly
2 parents 8a60268 + 9c7ae61 commit a9a4eb4

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

packages/microservices/client/client-redis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export class ClientRedis extends ClientProxy<RedisEvents, RedisStatus> {
5353
return `${pattern}.reply`;
5454
}
5555

56-
public close() {
57-
this.pubClient && this.pubClient.quit();
58-
this.subClient && this.subClient.quit();
56+
public async close() {
57+
this.pubClient && (await this.pubClient.quit());
58+
this.subClient && (await this.subClient.quit());
5959
this.pubClient = this.subClient = null;
6060
this.isManuallyClosed = true;
6161
this.pendingEventListeners = [];

packages/microservices/client/client-rmq.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export class ClientRMQ extends ClientProxy<RmqEvents, RmqStatus> {
9696
this.initializeDeserializer(options);
9797
}
9898

99-
public close(): void {
100-
this.channel && this.channel.close();
101-
this.client && this.client.close();
99+
public async close(): Promise<void> {
100+
this.channel && (await this.channel.close());
101+
this.client && (await this.client.close());
102102
this.channel = null;
103103
this.client = null;
104104
this.pendingEventListeners = [];

packages/microservices/test/client/client-redis.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,22 @@ describe('ClientRedis', () => {
195195
untypedClient.pubClient = pub;
196196
untypedClient.subClient = sub;
197197
});
198-
it('should close "pub" when it is not null', () => {
199-
client.close();
198+
it('should close "pub" when it is not null', async () => {
199+
await client.close();
200200
expect(pubClose.called).to.be.true;
201201
});
202-
it('should not close "pub" when it is null', () => {
202+
it('should not close "pub" when it is null', async () => {
203203
untypedClient.pubClient = null;
204-
client.close();
204+
await client.close();
205205
expect(pubClose.called).to.be.false;
206206
});
207-
it('should close "sub" when it is not null', () => {
208-
client.close();
207+
it('should close "sub" when it is not null', async () => {
208+
await client.close();
209209
expect(subClose.called).to.be.true;
210210
});
211-
it('should not close "sub" when it is null', () => {
211+
it('should not close "sub" when it is null', async () => {
212212
untypedClient.subClient = null;
213-
client.close();
213+
await client.close();
214214
expect(subClose.called).to.be.false;
215215
});
216216
});

packages/microservices/test/client/client-rmq.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@ describe('ClientRMQ', function () {
368368
untypedClient.client = { close: clientCloseSpy };
369369
});
370370

371-
it('should close channel when it is not null', () => {
372-
client.close();
371+
it('should close channel when it is not null', async () => {
372+
await client.close();
373373
expect(channelCloseSpy.called).to.be.true;
374374
});
375375

376-
it('should close client when it is not null', () => {
377-
client.close();
376+
it('should close client when it is not null', async () => {
377+
await client.close();
378378
expect(clientCloseSpy.called).to.be.true;
379379
});
380380
});

0 commit comments

Comments
 (0)