Skip to content

Guard configuration inspection reads with the data lock - #235

Merged
inhere merged 1 commit into
gookit:masterfrom
rupayon123:fix/lock-inspection-reads-20261028
Oct 28, 2026
Merged

inhere merged 1 commit into
gookit:masterfrom
rupayon123:fix/lock-inspection-reads-20261028

Conversation

@rupayon123

Copy link
Copy Markdown
Contributor

SetData replaces the config data under its write lock, but Exists, Keys, and IsEmpty read that data without taking the corresponding read lock. Calling these inspection methods alongside SetData produces data races; GetValue already takes the lock and passes the same concurrent control.

This adds read guards to the three inspection methods. The regression tests exercise concurrent map replacement and inspection, check that each read sees a complete configuration, and call the inspection methods from write hooks to guard against deadlocks. Data and Sub retain their existing live-map behavior.

Validation on Go 1.26.0 / macOS arm64:

  • The new concurrent tests report races before the fix and pass with -race after it, including five focused repetitions.
  • Full coverage and race suites pass: 196 leaf cases across nine packages; 96.9% statement coverage. go vet ./... and go build ./... pass.
  • Revive 1.11.0 with the workflow's default configuration and exclusion arguments exits 0, with the same 17 warnings as the unchanged base.
  • Unfiltered Staticcheck 2026.2.2 exits 1 on both the base and this branch, with the same three findings in unchanged issues_test.go (the deprecated yamlv3 import and two duration-variable names). No new findings or suppressions.

The Ubuntu/Go-version matrix and GitHub checks have not been run locally.

@inhere
inhere merged commit 88a1c0b into gookit:master Oct 28, 2026
12 checks passed
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.

2 participants