Redis: Fixed Crash During Data Loading and Memory Prefetching
Written by Alessio on 3/10/2024
Problem
During a replica full sync, a call to prefetchCommands() could crash the server. The code incorrectly assumed the first hash table was always valid, even while it was being emptied during data loading.
Solution
Added a check to skip memory prefetching if server.loading is true. During RDB loading, the main dictionary is being rebuilt, so prefetching keys is unnecessary. Also added a defensive assertion to prevent future issues.
Result
Redis no longer crashes during replica data loading, improving overall stability in high-load systems.
Commit: redis/redis@1abd489