Describe the bug
Potential memory leaks may occur when a replica node (that has received expired key writes) is switched to a primary node in Valkey. This memory leak is caused by the failure to clean up replicaKeysWithExpire when the node is promoted to primary, which results in this block of memory being unavailable for reuse.
To reproduce
- Prepare a Valkey with one primary node and at least one replica node.
- Write keys with expiration directly to the writable replica node.
- Promote this replica to primary before these keys expire.
- Monitor the memory usage after these keys have expired.
- Verify that the memory usage does not decrease as expected (even after expired keys should be cleaned up), indicating a memory leak.
Expected behavior
When a writable replica node is promoted to primary, the replicaKeysWithExpire on this node should be properly cleaned up. No abnormal memory leaks should occur, and the memory usage should align with the actual valid key data size.
Additional information
Long-running nodes may experience excessive memory usage, leading to OOM (Out-of-Memory) errors in extreme cases. The memory leak is only triggered when a replica with expired key writes is promoted to primary.
Describe the bug
Potential memory leaks may occur when a replica node (that has received expired key writes) is switched to a primary node in Valkey. This memory leak is caused by the failure to clean up
replicaKeysWithExpirewhen the node is promoted to primary, which results in this block of memory being unavailable for reuse.To reproduce
Expected behavior
When a writable replica node is promoted to primary, the
replicaKeysWithExpireon this node should be properly cleaned up. No abnormal memory leaks should occur, and the memory usage should align with the actual valid key data size.Additional information
Long-running nodes may experience excessive memory usage, leading to OOM (Out-of-Memory) errors in extreme cases. The memory leak is only triggered when a replica with expired key writes is promoted to primary.