fix: hold RLock during copy in Get to prevent concurrent map access - #406
Merged
knadh merged 1 commit intoMar 20, 2026
Merged
Conversation
…ap access The Get method released RLock before calling maps.Copy and copystructure.Copy on reference types (maps, slices, etc.), creating a race condition where concurrent writes could modify the underlying data during the copy. This caused "concurrent map read and map write" panics. Use defer to keep the read lock held until the copy completes. Also fixes a typo: "Skil" -> "Skip" in a comment. Fixes knadh#401 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Maks1mS
pushed a commit
to stplr-dev/stplr
that referenced
this pull request
Mar 22, 2026
This PR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [github.com/knadh/koanf/v2](https://github.com/knadh/koanf) | require | patch | `v2.3.3` → `v2.3.4` | [](https://securityscorecards.dev/viewer/?uri=github.com/knadh/koanf) | --- >⚠️ **Warning** > > Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/23) for more information. --- ### Release Notes <details> <summary>knadh/koanf (github.com/knadh/koanf/v2)</summary> ### [`v2.3.4`](https://github.com/knadh/koanf/releases/tag/v2.3.4) [Compare Source](knadh/koanf@v2.3.3...v2.3.4) #### What's Changed - Bump github.com/nats-io/nats-server/v2 from 2.10.27 to 2.11.12 in /providers/nats by [@​dependabot](https://github.com/dependabot)\[bot] in [#​400](knadh/koanf#400) - Bump filippo.io/edwards25519 from 1.1.0 to 1.1.1 in /providers/kiln by [@​dependabot](https://github.com/dependabot)\[bot] in [#​399](knadh/koanf#399) - Bump google.golang.org/grpc from 1.71.1 to 1.79.3 in /providers/etcd by [@​dependabot](https://github.com/dependabot)\[bot] in [#​405](knadh/koanf#405) - fix: hold RLock during copy in Get to prevent concurrent map access by [@​alexchenai](https://github.com/alexchenai) in [#​406](knadh/koanf#406) - Add ability to check for prior values in `cliflagv3.ProviderWithConfig()` just like `posflag` by [@​knadh](https://github.com/knadh) in [#​403](knadh/koanf#403) #### New Contributors - [@​alexchenai](https://github.com/alexchenai) made their first contribution in [#​406](knadh/koanf#406) **Full Changelog**: <knadh/koanf@v2.3.3...v2.3.4> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At 12:00 AM through 04:59 AM and 10:00 PM through 11:59 PM, Monday through Friday ( * 0-4,22-23 * * 1-5 ), Only on Sunday and Saturday ( * * * * 0,6 ) (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My43Ni4zIiwidXBkYXRlZEluVmVyIjoiNDMuNzYuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiS2luZC9EZXBlbmRlbmNpZXMiXX0=--> Reviewed-on: https://altlinux.space/stapler/stplr/pulls/370 Co-authored-by: Renovate Bot <[email protected]> Co-committed-by: Renovate Bot <[email protected]>
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
Get()where theRLockwas released beforemaps.Copy()andcopystructure.Copy()operated on reference types (maps, slices, etc.), allowing concurrent writes to causefatal error: concurrent map read and map writepanics.defer ko.mu.RUnlock()so the read lock is held for the entire duration of the copy operations, matching the pattern already used byAll()andRaw().Details
The
Getmethod previously did:This created a window where a concurrent
Load/Set/Deletecould modify the underlying map whileCopywas iterating it. The fix changes todefer ko.mu.RUnlock()so the lock covers the copy operations.Fixes #401
Test plan
go vet ./...passesgo build ./...passesgo test -racewith CGO enabled to reproduce reliably🤖 Generated with Claude Code