Conversation
…Map.Clear - Iter2: move counter inside returned closure so index resets on reuse - Locked.Clone/LockedOrdered.Clone: remove outer RLock to prevent recursive read-lock deadlock under write contention - Ordered.UnmarshalJSON: use Add() loop to deduplicate, preventing internal state corruption from duplicate JSON values - Chunk: panic early with clear message on n <= 0 instead of division-by-zero inside the iterator - SyncMap.Clear: delete during Range for atomic count accuracy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes five correctness bugs discovered during code review, focusing on iterator behavior, concurrency issues, and data structure invariants.
Changes:
- Fixed Iter2 to reset index counter on each iterator reuse by moving the counter variable inside the returned closure
- Removed recursive read-lock deadlock in Locked.Clone and LockedOrdered.Clone by removing redundant outer RLock calls
- Fixed Ordered.UnmarshalJSON to properly deduplicate JSON arrays with duplicate values using Add() instead of direct slice assignment
- Added early panic with clear error message for invalid Chunk parameters (n <= 0)
- Fixed SyncMap.Clear to delete elements during Range iteration for accurate count instead of separate count-then-clear operations
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| set.go | Moved Iter2 counter variable inside closure for proper reset on reuse; added panic check for Chunk with n <= 0 |
| set_test.go | Added TestIter2ReusedIteratorResetsIndex to verify index counter resets correctly |
| locked.go | Removed redundant outer RLock from Clone to prevent recursive lock deadlock |
| locked_ordered.go | Removed redundant outer RLock from Clone to prevent recursive lock deadlock |
| ordered.go | Changed UnmarshalJSON to use Add() loop instead of direct slice assignment to maintain idx/values invariant |
| sync.go | Refactored Clear to delete during Range for accurate concurrent count; reformatted var declarations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RLockthat caused recursive read-lock deadlock under write contention (the innerIteratorcall already acquiresRLock)Add()in a loop instead of direct slice assignment, so duplicate values in JSON input are deduplicated rather than corrupting internal state (len(values) != len(idx))n <= 0instead of hitting a cryptic division-by-zero inside the iteratorRangeinstead of counting first then callingClear()separately, so the returned count accurately reflects what was removedTest plan
TestIter2ReusedIteratorResetsIndexto verify index resets on iterator reuse-raceflag🤖 Generated with Claude Code