Improve resource management for Client-Side Caching and fix RediSearch memory corruption #3526#3624
Open
YoHanKi wants to merge 4 commits intoredis:mainfrom
Open
Improve resource management for Client-Side Caching and fix RediSearch memory corruption #3526#3624YoHanKi wants to merge 4 commits intoredis:mainfrom
YoHanKi wants to merge 4 commits intoredis:mainfrom
Conversation
- [Caching] Explicitly remove PushListener from connection on DefaultRedisCache.close() to prevent memory leaks (Fixes redis#3526). - [Caching] Add 'closeConnection' flag to ClientSideCaching and DefaultRedisCache to allow shared connection scenarios. - [RediSearch] Implement ByteBuffer copying in EncodedComplexOutput to prevent SIGSEGV/JVM crashes caused by Netty pooled buffer reclamation during parsing. - Maintain backward compatibility by keeping 'closeConnection' default as true. Signed-off-by: YoHanKi <alcuz137@gmail.com>
- Add DefaultRedisCacheUnitTests to verify listener removal and connection closing logic using Mockito. - Add testSearchWithLargeJsonPayloads to RediSearchIntegrationTests to verify memory safety and correct parsing of large search results. - Ensure all new test classes follow project conventions, including License headers and @tag usage. Signed-off-by: YoHanKi <alcuz137@gmail.com>
- Reformat RediSearchIntegrationTests.java using 'formatter:format' to comply with project conventions. Signed-off-by: YoHanKi <alcuz137@gmail.com>
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
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.
Make sure that:
mvn formatter:formattarget. Don’t submit any formatting related changes.Description
This PR addresses two critical issues related to resource management and memory safety:
1. Improve Resource Management in Client-Side Caching (#3526)
DefaultRedisCachedid not removePushListenerfrom the connection when closed, leading to potential memory leaks and redundant invalidation logic. Also, closing aCacheFrontendforcibly closed the underlying connection, which is problematic for shared connection scenarios.DefaultRedisCacheto track and explicitly remove all registered listeners duringclose().closeConnectionoption (defaulting totruefor backward compatibility) to allow users to decide whether the underlying Redis connection should be closed along with the cache.DefaultRedisCacheUnitTeststo verify listener removal and connection management.2. Fix Memory Corruption/JVM Crash in RediSearch
EncodedComplexOutputwas storing read-only views of Netty's pooledByteBuffers. These buffers could be reclaimed or reused before parsing was complete, leading toSIGSEGVor data corruption, especially on Linux/Ubuntu environments with Netty 4.2+.EncodedComplexOutputto explicitly copy theByteBuffercontent into a new heap-allocated buffer before storing it, ensuring data persistence during the parsing phase.testSearchWithLargeJsonPayloadstoRediSearchIntegrationTestsand verified the fix in an Ubuntu-based Docker environment with Netty 4.2.4.Final andPARANOIDleak detection.Changes
ClientSideCaching: Added overloads forenableandcreatewithcloseConnectionparameter.DefaultRedisCache: Implemented listener tracking and removal, addedcloseConnectionlogic.EncodedComplexOutput: ImplementedByteBuffercopying.DefaultRedisCacheUnitTests: New unit tests for caching resource management.RediSearchIntegrationTests: Added stress test for large JSON payloads.Fixes #3526