Skip to content

Fix cached master ownership lifecycle - #1

Merged
ADovgalyuk merged 4 commits into
mainfrom
agent/fix-cached-master-lifecycle
Jul 28, 2026
Merged

Fix cached master ownership lifecycle#1
ADovgalyuk merged 4 commits into
mainfrom
agent/fix-cached-master-lifecycle

Conversation

@ADovgalyuk

Copy link
Copy Markdown
Owner

Summary

Centralize disposal of redisMaster::cached_master in replicationDiscardCachedMaster() and transfer ownership before scheduling asynchronous client destruction.

Root cause

replicationCacheMasterUsingMyself() and replicationCacheMasterUsingMaster() called freeClient(mi->cached_master) without clearing the field. The existing safeguard in replicationCreateMasterClient() then observed the stale non-null pointer and queued the same client through freeClientAsync(), creating a double-free/use-after-free lifecycle.

Changes

  • Make replicationDiscardCachedMaster() clear mi->cached_master before touching or asynchronously freeing the client.
  • Route both cached-master reconstruction paths through that helper.
  • Keep a defensive discard and invariant check in replicationCreateMasterClient().
  • Remove direct freeClient(mi->cached_master) calls from the reconstruction paths.

Validation

  • git diff --check executed while generating the commit.
  • Repository CI will build KeyDB and run the configured unit-test set.

Related upstream context: Snapchat#896.

@ADovgalyuk
ADovgalyuk marked this pull request as ready for review July 28, 2026 18:07
@ADovgalyuk
ADovgalyuk merged commit 3336de9 into main Jul 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant