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

Conversation

janroker
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

When calling close() on ClientRedis, the isManuallyClosed flag is set after awaiting the quit() calls on the Redis clients. If Redis emits the 'end' event during or after quit(), event handlers may see isManuallyClosed as false and incorrectly log errors or attempt reconnection logic. This creates a race condition and can result in misleading error logs during a normal shutdown.

What is the new behavior?

The isManuallyClosed flag is now set to true before calling quit() on the Redis clients. This ensures that any event handlers triggered during shutdown will see the correct state and will not log errors or attempt reconnection when the shutdown is intentional.

Additional tests have been added to verify this behavior and prevent regressions.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@janroker janroker force-pushed the fix/prevent-error-logs-during-redis-client-shutdown branch from 0e4e802 to 5724a5a Compare May 20, 2025 13:56
@coveralls
Copy link

coveralls commented May 20, 2025

Pull Request Test Coverage Report for Build 8ecb4057-9687-4b27-ab7b-85339b5058e7

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 88.94%

Totals Coverage Status
Change from base Build 16a83cd7-0397-4555-852d-e8667ea8a43e: 0.0%
Covered Lines: 7197
Relevant Lines: 8092

💛 - Coveralls

@janroker janroker force-pushed the fix/prevent-error-logs-during-redis-client-shutdown branch from 5724a5a to 1e5e2bb Compare May 20, 2025 14:06
@kamilmysliwiec kamilmysliwiec merged commit 9e24342 into nestjs:master May 21, 2025
3 checks passed
@kamilmysliwiec
Copy link
Member

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants