Repository navigation
Fix concurrent map access in NBSetupKey controller - #436
odysseymorphey wants to merge 2 commits into
Conversation
ReferencedSecrets is written by Reconcile and read by the Secret watch map function, which run in different goroutines. A Secret event that arrives while a reconcile is updating the map makes the Go runtime abort the operator with "fatal error: concurrent map read and map write". Guard the map with a RWMutex and move the map function into a method so it can be tested against a concurrent reconcile. Fixes netbirdio#435
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation |
|---|---|---|
| Linked Issues check | ✅ Passed | The change satisfies issue [#435]. Reconcile protects deletion and insertion in ReferencedSecrets with referencedSecretsMu.Lock. mapSecretToNBSetupKey protects lookup with RLock. `SetupWithM… |
| Out of Scope Changes check | ✅ Passed | The reviewed changes stay within issue [#435]. They add synchronization for ReferencedSecrets, extract the Secret mapping callback for use and testing, and add the related concurrency regression tes… |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and concisely describes the main change: fixing concurrent map access in the NBSetupKey controller. |
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
A rabbit watched the secrets flow,
While locks kept reads and writes in tow.
Reconcile ran, events came by,
The map stayed safe as time went by.
Then hopped the rabbit, pleased to see.
Comment @coderabbitai help to get the list of available commands.
Fixes #435
ReferencedSecretsis written byReconcileand read by the Secret watch map function, which run in different goroutines. A Secret event that arrives while a reconcile is updating the map makes the Go runtime abort the operator withfatal error: concurrent map read and map write.Changes
ReferencedSecretswith async.RWMutex: write lock inReconcile, read lock in the map function.SetupWithManagerinto themapSecretToNBSetupKeymethod so it can be tested.ReconcileandmapSecretToNBSetupKeyconcurrently.Testing
go testhits the same fatal error as in the issue in 4 of 5 runs, andgo test -racereports the data race every time.-raceruns of the NBSetupKey specs pass.make lint,make test-unit,go mod tidyandmake -B generatepass with no extra changes.Could a maintainer add the
changelog/fixedlabel?Summary by CodeRabbit