Skip to content

fix: unlock the node when eq panics in CompareAndDelete - #13

Merged
darxnet merged 1 commit into
mainfrom
fix/backfill-2026-11
Nov 12, 2026
Merged

darxnet merged 1 commit into
mainfrom
fix/backfill-2026-11

Conversation

@darxnet

@darxnet darxnet commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Fixes found in a one-off review of competitor issues over their whole history; each bug is reproduced by a regression test that failed before the fix.

Changes

  • fix: unlock the node when eq panics in CompareAndDelete

Notes

  • Deviates from upstream internal/sync.HashTrieMap, which unlocks explicitly on each path and has the same hazard (a non-comparable dynamic value in sync.Map also panics there).
  • No new allocations (TestNoAlloc extended); the mismatch path measured ~16.0→17.4 ns, within noise.

Testing

go vet, golangci-lint run and go test -race ./... pass locally.

CompareAndDelete called eq with the key's trie node locked and unlocked
it only on the normal return paths, so a panicking eq - or == on a
ComparableMap[K, any] value whose dynamic type is not comparable, such
as []byte - left the node locked once the caller recovered, and every
later write to that subtree blocked forever. The unlock is now deferred
unless pruneEmpty takes the lock over.

CompareAndSwap and LoadOrCompute already defer the unlock; a regression
test now covers all three. The doc comments now say where eq runs:
CompareAndSwap calls it once without the lock to find the entry and again
with it, so in both methods it must not use the map.

Deviation from upstream internal/sync.HashTrieMap: upstream
CompareAndDelete unlocks explicitly on each path, as this code did. It
only compares values with the runtime's type equality, so the same
hazard exists there for sync.Map values of a non-comparable dynamic type;
here eq is arbitrary user code, so the unlock is deferred.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@darxnet
darxnet merged commit 545eba1 into main Nov 12, 2026
9 checks passed
@darxnet
darxnet deleted the fix/backfill-2026-11 branch November 12, 2026 12:59
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