-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix: RedisCacheAdapter put, del and clear reject on a Redis outage #10635
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
Open
AdrianCurtin
wants to merge
1
commit into
parse-community:alpha
Choose a base branch
from
AdrianCurtin:fix_redis_cache_adapter_error_handling
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−15
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: parse-community/parse-server
Length of output: 166
🏁 Script executed:
Repository: parse-community/parse-server
Length of output: 20549
🏁 Script executed:
Repository: parse-community/parse-server
Length of output: 26360
🏁 Script executed:
Repository: parse-community/parse-server
Length of output: 13252
🌐 Web query:
site:github.com/parse-community/parse-server "RedisCacheAdapter error handling" "Redis is unavailable"💡 Result:
When using a RedisCacheAdapter (commonly associated with systems like Parse Server), Redis becoming unavailable can cause the application to crash or fail to reconnect if proper error handling is not implemented. The primary issues stem from how Redis client libraries (particularly version 4.x and newer of node-redis) handle connection events [1][2][3]. Key strategies for handling Redis unavailability include: 1. Registering Event Handlers: Modern Redis clients require explicit error and connection event handlers to function correctly and auto-reconnect [2][3]. Failing to attach these handlers can cause unhandled exceptions that crash the process [1][4]. Essential handlers typically include: - error: Logs or handles connection errors [1][2]. - connect/reconnecting: Provides visibility into the connection state [1][4]. - ready: Confirms the client is ready to perform operations [1][4]. 2. Configuring Retry Strategies: Most Redis clients support a retry_strategy configuration, which allows you to define how many times the client should attempt to reconnect and how long to wait between attempts [5]. This prevents the application from entering a permanent failed state [5]. 3. Implementing Graceful Fallback: If Redis is unavailable for extended periods, some implementations consider falling back to a direct database query [6]. While this keeps the application operational during outages, it introduces challenges such as managing stale data once the Redis instance recovers [6]. 4. Maintenance: Ensure your Redis client library is updated and that the adapter configuration aligns with the specific version requirements of the client [1][2]. If using a framework like Parse Server, verify that you are on a version that includes the necessary fixes for Redis 4.x reconnect handling [1][4].
Citations:
🌐 Web query:
site:github.com/parse-community/parse-server RedisCacheAdapter reject Redis failures put del clear💡 Result:
In the Parse Server
RedisCacheAdapter, the operationsput,del, andcleardo not explicitly reject or throw errors that halt the server when a Redis failure occurs, provided the Redis client is configured with appropriate event listeners [1][2]. Historically, unhandled errors in the Redis client (such as connection losses) could cause theRedisCacheAdapteror the entire server to crash [1][3]. To address this, current implementations include required event handlers for the Redis client (specificallyerror,connect,reconnecting, andready) to ensure the client can log errors and attempt reconnection without crashing the process [1][4][2]. Key behavior regarding failures: - Error Handling: The adapter is designed to catch and log errors during operations likegetto prevent the application from crashing [5]. Forput,del, and other operations, the adapter relies on the underlyingnode-redisclient's ability to manage connections and emit error events [1][6]. - Operational Impact: If Redis goes down,RedisCacheAdapteroperations may fail silently or result in logged errors, but they generally do not "reject" in a way that terminates the request-response cycle, unless the calling code is specifically designed to handle or bubble up those promise rejections [3][5]. - Graceful Degradation: There is no native "graceful fallback" mechanism in the standardRedisCacheAdapterthat automatically switches to a database query upon Redis failure [3]. If Redis is unavailable, cache operations will essentially fail, potentially leading to increased load on the primary database [3]. If you are encountering crashes, it is likely due to an outdated version of the adapter lacking the necessary Redis client error listeners or an unhandled promise rejection in the calling code [1][6]. Ensure your environment uses a version of Parse Server that includes the Redis 4/5 reconnection fixes [4][2].Citations:
🏁 Script executed:
Repository: parse-community/parse-server
Length of output: 6774
🏁 Script executed:
Repository: parse-community/parse-server
Length of output: 1262
Rethrow Redis write failures and handle all affected callers.
These catches still resolve with
undefinedafter logging. Addthrow errafter each log. Handle every unawaited call before applying this contract, including calls inAuth,rest.js,RestWrite, andPurgeRouter. Update the outage tests to expect rejection and remove the swallowed-rejection test.🤖 Prompt for AI Agents