Fix defrag issues for pubsub and lua#14330
Merged
sundb merged 4 commits intoredis:unstablefrom Sep 7, 2025
Merged
Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes defragmentation issues for pubsub and lua functionality that were introduced by a previous change. The fix addresses problems where memory defragmentation could reallocate objects that were still being referenced, leading to potential use-after-free scenarios.
- Moved lua script execution to occur after LRU list manipulation to prevent accessing reallocated memory
- Added a new dictionary lookup function that uses pointer comparison instead of key comparison for defrag scenarios
- Updated pubsub defrag callback to use the new lookup method to handle reallocated channel names
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/eval.c | Reordered lua script execution and LRU operations, added safety comment about memory reallocation |
| src/dict.h | Added declaration for new dictFindByHashAndPtr function |
| src/dict.c | Implemented dictFindByHashAndPtr function for pointer-based dictionary lookups |
| src/defrag.c | Updated pubsub defrag callback to use hash and pointer lookup instead of key-based lookup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
oranagra
approved these changes
Sep 4, 2025
YaacovHazan
pushed a commit
to YaacovHazan/redis
that referenced
this pull request
Sep 28, 2025
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by redis#13058 1. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by redis#13058 This fix follows redis#14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
sundb
added a commit
to YaacovHazan/redis
that referenced
this pull request
Sep 30, 2025
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by redis#13058 1. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by redis#13058 This fix follows redis#14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
sundb
added a commit
to YaacovHazan/redis
that referenced
this pull request
Sep 30, 2025
This PR fixes two defrag issues. 1. Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated. This issue was introduced by redis#13058 2. Fix potential use-after-free for lua during AOF loading with defrag This issue was introduced by redis#13058 This fix follows redis#14319 This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
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.
This PR fixes two defrag issues.
Fix a use-after-free issue caused by updating dictionary keys after a pubsub channel is reallocated.
This issue was introduced by Implement defragmentation for pubsub kvstore #13058
Fix potential use-after-free for lua during AOF loading with defrag
This issue was introduced by Implement defragmentation for pubsub kvstore #13058
This fix follows Fix crash during lua script defrag #14319
This PR updates the LuaScript LRU list before script execution to prevent accessing a potentially invalidated pointer after long-running scripts.
Note that both of these issues were introduced since 7.4, so we can fix them together.