Skip to content

Conversation

@Nek-11
Copy link
Contributor

@Nek-11 Nek-11 commented Nov 26, 2025

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 UsageCacheManager's Redis connection would prematurely close due to idle timeouts, leading to application crashes. By integrating keepAlive and pingInterval configurations into the Redis client setup, consistent with other parts of the system, the PR significantly enhances the robustness of Redis connections. This is particularly beneficial for deployments on cloud platforms that enforce strict idle timeout policies, such as Azure Cache for Redis, ensuring continuous and reliable operation.

Highlights

  • Problem Addressed: This pull request resolves the 'Socket closed unexpectedly' error in UsageCacheManager when using Redis, particularly on platforms like Azure Cache for Redis which enforce idle timeouts.
  • Root Cause Identified: The UsageCacheManager was found to be missing keepAlive and pingInterval configurations for its Redis connection, a similar issue previously fixed in other parts of the codebase (e.g., RedisEventPublisher, RedisEventSubscriber).
  • Solution Implemented: The fix involves adding keepAlive and pingInterval options to the Redis client configuration within UsageCacheManager.ts, utilizing the existing REDIS_KEEP_ALIVE environment variable for consistency.
  • Configuration Coverage: The keepAlive and pingInterval settings are applied to both REDIS_URL and individual REDIS_HOST/REDIS_PORT Redis connection configurations.
  • Verification: The changes were thoroughly tested in a local Docker environment with a short Redis timeout and confirmed on an Azure Web App with Azure Cache for Redis, ensuring connection stability and the absence of the 'Socket closed unexpectedly' errors.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@HenryHengZJ HenryHengZJ merged commit 069ba28 into FlowiseAI:main Nov 27, 2025
2 checks passed
@Nek-11 Nek-11 deleted the fix/usagecachemanager-redis-keepalive branch December 2, 2025 14:37
davehamptonusa pushed a commit to davehamptonusa/Flowise that referenced this pull request Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants