fix(plugin/kubernetes): prevent data race on applications map in livestate store - #7283
Open
Vishakha7-Kumari wants to merge 1 commit into
Open
fix(plugin/kubernetes): prevent data race on applications map in livestate store#7283Vishakha7-Kumari wants to merge 1 commit into
Vishakha7-Kumari wants to merge 1 commit into
Conversation
…state store Signed-off-by: Vishakha7-Kumari <singhdaisy669@gmail.com>
✅ Deploy Preview for pipecd-site canceled.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a concurrency issue in the PipeCD pipedv1 Kubernetes plugin live state store by ensuring deployTargetResources.getApplicationResources only mutates the applications map under a write lock, and adds tests to validate safe concurrent access.
Changes:
- Fix map mutation under
RWMutexread lock by adding lock upgrade + double-check logic ingetApplicationResources. - Add unit tests for
getApplicationResources, including a concurrent access test to guard against regressions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/app/pipedv1/plugin/kubernetes/livestate/store/store.go | Uses a write lock (with double-check) before initializing/inserting missing applications map entries to prevent concurrent map writes. |
| pkg/app/pipedv1/plugin/kubernetes/livestate/store/store_test.go | Adds coverage for basic behavior and concurrent calls to getApplicationResources. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -0,0 +1,65 @@ | |||
| // Copyright 2026 The PipeCD Authors. | |||
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.
What this PR does / Why we need it
This PR fixes a concurrency bug in deployTargetResources.getApplicationResources in the pipedv1 Kubernetes plugin live state store.
Previously, getApplicationResources attempted to initialize and insert missing entries into s.applications while only holding a read lock (s.mu.RLock()). In Go, mutating a map under a read lock creates a data race that can crash the piped process with atal error: concurrent map writes when multiple goroutines access application resources concurrently.
This change:
ewApplicationResources(s.deployTarget).
Changes
Signed-off-by: Vishakha7-Kumari singhdaisy669@gmail.com