Skip to content

crossbeam-skiplist: fix RefRange iterator memory leak (#19284)#19293

Merged
ti-chi-bot[bot] merged 4 commits intotikv:release-8.5-20251208-v8.5.4from
ti-chi-bot:cherry-pick-19284-to-release-8.5-20251208-v8.5.4
Jan 20, 2026
Merged

crossbeam-skiplist: fix RefRange iterator memory leak (#19284)#19293
ti-chi-bot[bot] merged 4 commits intotikv:release-8.5-20251208-v8.5.4from
ti-chi-bot:cherry-pick-19284-to-release-8.5-20251208-v8.5.4

Conversation

@ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #19284

What is changed and how it works?

Issue Number: Close #19285

What's Changed:

Fix a memory leak in crossbeam-skiplist's RefRange iterator.

RefRange::next() and next_back() were using clone_from() to update self.head/self.tail. Since RefEntry has no Drop implementation (by design - callers must explicitly call release()), the old entry was dropped without decrementing its refcount, causing permanent memory leaks.
Note that the the comment of RefEntry says

/// You *must* call `release` to free this type, otherwise the node will be
/// leaked. This is because releasing the entry requires a `Guard`.

This bug affects any code using SkipMap::range() iterators. In TiKV, this manifests as memory leaks in LockTable when check_range() or find_first() are called.

// Before (buggy):
self.head.clone_from(&next_head);  // Old entry dropped without decrement!

// After (fixed):
if let Some(e) = mem::replace(&mut self.head, next_head.clone()) {
    unsafe { e.node.decrement(guard); }  // Properly decrement old entry
}

The fix matches the pattern already used in RefIter::next().

Stress test results (10 seconds, range iteration + insert/remove cycle):

before fix:
t=10s ops=11710 len=3422 alloc=613MB
after fix:
t=10s ops=11786 len=7530 alloc=3MB
Fix RefRange::next() and next_back() to properly decrement old self.head/self.tail refcount.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

Fix a memory leak in crossbeam-skiplist's RefRange iterator that caused LockTable memory to grow unboundedly when using range queries.

RefRange::next() and next_back() were using clone_from() to update
self.head/self.tail. Since RefEntry has no Drop implementation,
the old entry was dropped without decrementing its refcount, causing
permanent memory leaks.

Fix by using mem::replace() and manually calling decrement() on the
old entry, matching the pattern used in RefIter::next().

Signed-off-by: ekexium <eke@fastmail.com>
@ti-chi-bot ti-chi-bot added dco-signoff: yes Indicates the PR's author has signed the dco. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-8.5-20251208-v8.5.4 labels Jan 19, 2026
@ekexium ekexium requested review from cfzjywxk and overvenus January 19, 2026 09:27
ekexium and others added 3 commits January 19, 2026 17:29
Signed-off-by: ekexium <eke@fastmail.com>
…pments. (tikv#19248)

ref tikv#19249

Upgrades the `cargo-deny` version and ignore some errors.

Signed-off-by: lucasliang <nkcs_lykx@hotmail.com>
ref tikv#19249

Fix the CI by ignoring `RUSTSEC-2026-0002`.

Signed-off-by: you06 <you1474600@gmail.com>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 19, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 20, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, overvenus

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-19 10:54:08.318276416 +0000 UTC m=+404875.932233262: ☑️ agreed by overvenus.
  • 2026-01-20 01:42:53.700080693 +0000 UTC m=+458201.314037550: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit d25f155 into tikv:release-8.5-20251208-v8.5.4 Jan 20, 2026
4 checks passed
@ti-chi-bot ti-chi-bot bot deleted the cherry-pick-19284-to-release-8.5-20251208-v8.5.4 branch January 20, 2026 01:47
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2026

@ti-chi-bot: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test 736b138 link unknown /test pull-unit-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-8.5-20251208-v8.5.4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants