Fix Redis crash loop from unhandled socket errors#18
Open
UsamaSadiq wants to merge 2 commits into
Open
Conversation
node-redis session and cache clients crash the process when Memorystore drops idle TLS connections. Add error handlers, pingInterval, TCP keepalive, and reconnect strategy to both the session-storage and cache-storage Redis clients.
089c3b9 to
8645ab6
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Twenty pods crash-loop on the FOSS sandbox because the node-redis clients (session storage and cache storage) lack error handlers. When Memorystore (Valkey) drops idle TLS connections, node-redis emits an
errorevent with no listener, which Node treats as fatal (exit 1). The.connect().catch()in session storage also re-throws, producing an unhandled rejection that breaks built-in auto-reconnect.This patch fixes both the session-storage (
connect-redis) and cache-storage (cache-manager-redis-yet) Redis clients:.on('error', ...)handler to both clients to prevent unhandled error crashes.catch()with log-only handler so auto-reconnect works (session client)redisStore(which creates its own client without error handling) toredisInsStorewith a pre-built client that has a proper error handler attachedpingInterval: 30sto keep idle connections alive and avoid Memorystore reapingsocket.keepAlive+keepAliveInitialDelayfor TCP-level keepalivesocket.reconnectStrategywith exponential backoff capped at 5sThe ioredis clients (BullMQ, pub/sub) are not affected -- they have built-in reconnect and error handling.
Testing
Session Redis client error:/Cache Redis client error:lines (expected, non-fatal) instead ofSocketClosedUnexpectedlyErrorstack traces