-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
redis_keep_alive fix on usagecachemanager using keyv/redis #5519
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
redis_keep_alive fix on usagecachemanager using keyv/redis #5519
Conversation
Summary of ChangesHello @Nek-11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical stability issue where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively resolves a critical issue where Redis connections were being dropped due to idle timeouts, by correctly configuring keepAlive and pingInterval for the UsageCacheManager. The fix is applied consistently for both Redis URL and host/port configurations. My review includes a suggestion to refactor the duplicated logic for parsing the REDIS_KEEP_ALIVE environment variable. This will improve code clarity and maintainability without changing the functionality.
Problem:
The UsageCacheManager.ts file (introduced after v3.0.0) creates a Redis connection via @keyv/redis when running in queue mode (MODE=queue), but does not configure keepAlive or pingInterval options. This causes the Redis connection to be closed by the server after the idle timeout period (e.g., 15 minutes on Azure Cache for Redis), resulting in a fatal Socket closed unexpectedly crash.
This is the same root cause as #4377 and #4431 , which fixed the issue for RedisEventPublisher, RedisEventSubscriber and others. However, UsageCacheManager was added later and was missing the same keepAlive configuration.
The error manifests as:
uncaughtException: Socket closed unexpectedlyError: Socket closed unexpectedly at Socket. (node_modules/.pnpm/@redis[email protected]/node_modules/@redis/client/dist/lib/client/socket.js:194:118)
This particularly affects Azure Web Apps deployments using Azure Cache for Redis, which has a fixed idle timeout that cannot be disabled.
Solution:
Added keepAlive and pingInterval configuration to the Redis client options in UsageCacheManager.ts, using the existing REDIS_KEEP_ALIVE environment variable for consistency with the rest of the codebase.
The fix applies to both:
REDIS_URL configuration path
Individual REDIS_HOST/REDIS_PORT configuration path
Testing:
Deployed to local Docker environment with Redis timeout set to 30 seconds
Verified connection remains stable after multiple idle timeout periods
Confirmed no Socket closed unexpectedly errors after extended idle periods
Tested with REDIS_KEEP_ALIVE=15000 (15 seconds)
Tested and confirmed on Azure Web App with Azure Cache for Redis