Skip to content

fix(microservice): prevent error logs during redis client shutdown #15166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/microservices/client/client-redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export class ClientRedis extends ClientProxy<RedisEvents, RedisStatus> {
}

public async close() {
this.isManuallyClosed = true;
this.pubClient && (await this.pubClient.quit());
this.subClient && (await this.subClient.quit());
this.pubClient = this.subClient = null;
this.isManuallyClosed = true;
this.pendingEventListeners = [];
}

Expand Down
30 changes: 30 additions & 0 deletions packages/microservices/test/client/client-redis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,36 @@ describe('ClientRedis', () => {
await client.close();
expect(subClose.called).to.be.false;
});
it('should have isManuallyClosed set to true when "end" event is handled during close', async () => {
let endHandler: Function | undefined;
sub.on = (event, handler) => {
if (event === 'end') endHandler = handler;
};
sub.quit = async () => {
if (endHandler) {
endHandler();
expect(untypedClient.isManuallyClosed).to.be.true;
}
};
client.registerEndListener(sub);
await client.close();
});

it('should not log error when "end" event is handled during close', async () => {
let endHandler: Function | undefined;
const logError = sinon.spy(untypedClient.logger, 'error');
sub.on = (event, handler) => {
if (event === 'end') endHandler = handler;
};
sub.quit = async () => {
if (endHandler) {
endHandler();
}
};
client.registerEndListener(sub);
await client.close();
expect(logError.called).to.be.false;
});
});
describe('connect', () => {
let createClientSpy: sinon.SinonSpy;
Expand Down