Skip to content

fix: reclaim entries when duplicate key destructors panic - #409

Merged
tisonkun merged 3 commits into
apache:mainfrom
tisonkun:codex/fix-duplicate-key-panic
Nov 6, 2026
Merged

tisonkun merged 3 commits into
apache:mainfrom
tisonkun:codex/fix-duplicate-key-panic

Conversation

@tisonkun

@tisonkun tisonkun commented Nov 5, 2026

Copy link
Copy Markdown
Member

Summary

Establish cleanup ownership before explicitly dropping duplicate keys outside the table locks in OnceMap and singleflight::Group. A panicking key destructor now releases pending entries and cached value clones, including when another caller cancels during that destructor, while the panic continues to propagate.

Add deterministic regression coverage for compute, try_compute, work, try_work, and cached lookups, and record the fix in the changelog.

Fixes #388.

Validation: all three new regression tests fail before the fix and pass afterward; cargo x test passes on stable and Rust 1.86.0 (688 tests each), cargo x check and cargo x lint pass, and the three regression tests pass under Miri with strict provenance and symbolic alignment checks.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

No open issues 🎉

What changed in this PR

Fixes potential leaks in OnceMap and singleflight::Group when dropping a duplicate key triggers a panic, by establishing cleanup ownership before dropping the key outside internal locks, and adds regression tests plus a changelog entry.

Changes:

  • Adjust OnceMap and singleflight::Group internals to create cleanup guards before explicitly dropping duplicate keys outside the lock.
  • Add KeyWithDrop test helper to deterministically trigger panicking key destructors.
  • Add regression tests covering pending computations/work and cached lookups, and record the fix in the changelog.
File Description
asyncband/​src/​test_support.rs Adds KeyWithDrop helper to trigger controlled panics during key drop.
asyncband/​src/​singleflight/​tests.rs Adds regression test for duplicate-key destructor panic cleanup in Group.
asyncband/​src/​singleflight/​mod.rs Refactors duplicate-key path to establish WorkCleanupGuard ownership before dropping the key.
asyncband/​src/​once/​once_map/​tests.rs Adds regression tests for pending and cached scenarios involving duplicate-key destructor panics.
asyncband/​src/​once/​once_map/​mod.rs Refactors lookup path to return a pending cleanup guard and drop duplicate keys only after ownership is established.
CHANGELOG.md Documents the bug fix.

Review effort: Lite

@orthur2 orthur2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread asyncband/src/once/once_map/tests.rs Resolved
@tisonkun
tisonkun enabled auto-merge (squash) November 6, 2026 15:15
@tisonkun
tisonkun merged commit cbdcd0f into apache:main Nov 6, 2026
9 checks passed
@tisonkun
tisonkun deleted the codex/fix-duplicate-key-panic branch November 6, 2026 15:29
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.

OnceMap and singleflight leak an entry when a duplicate key's destructor panics

3 participants