Skip to content

Commit 1e5e2bb

Browse files
author
Jan Rocek
committed
fix(microservices): prevent error logs during redis client shutdown
1 parent 6fe958d commit 1e5e2bb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/microservices/client/client-redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export class ClientRedis extends ClientProxy<RedisEvents, RedisStatus> {
5454
}
5555

5656
public async close() {
57+
this.isManuallyClosed = true;
5758
this.pubClient && (await this.pubClient.quit());
5859
this.subClient && (await this.subClient.quit());
5960
this.pubClient = this.subClient = null;
60-
this.isManuallyClosed = true;
6161
this.pendingEventListeners = [];
6262
}
6363

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,36 @@ describe('ClientRedis', () => {
213213
await client.close();
214214
expect(subClose.called).to.be.false;
215215
});
216+
it('should have isManuallyClosed set to true when "end" event is handled during close', async () => {
217+
let endHandler: Function | undefined;
218+
sub.on = (event, handler) => {
219+
if (event === 'end') endHandler = handler;
220+
};
221+
sub.quit = async () => {
222+
if (endHandler) {
223+
endHandler();
224+
expect(untypedClient.isManuallyClosed).to.be.true;
225+
}
226+
};
227+
client.registerEndListener(sub);
228+
await client.close();
229+
});
230+
231+
it('should not log error when "end" event is handled during close', async () => {
232+
let endHandler: Function | undefined;
233+
const logError = sinon.spy(untypedClient.logger, 'error');
234+
sub.on = (event, handler) => {
235+
if (event === 'end') endHandler = handler;
236+
};
237+
sub.quit = async () => {
238+
if (endHandler) {
239+
endHandler();
240+
}
241+
};
242+
client.registerEndListener(sub);
243+
await client.close();
244+
expect(logError.called).to.be.false;
245+
});
216246
});
217247
describe('connect', () => {
218248
let createClientSpy: sinon.SinonSpy;

0 commit comments

Comments
 (0)