Fix two potential race conditions in project-related code#171
Conversation
Avoid races with other code that uses the global `scheme.Scheme` by creating a fresh scheme for the control plane client. This allows us to safely create dev control planes concurrently with other operations. Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
We generate schemas for all languages concurrently and previously wrote to the `schemas` map without coordination. Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
📝 WalkthroughWalkthroughTwo independent bug fixes: ChangesExplicit Kubernetes scheme for controller-runtime client
Concurrent map write protection in schema generation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/project/controlplane/controlplane.go (1)
341-345: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winReturn the
AddToSchemeerror fromnewSchemeinternal/project/controlplane/controlplane.go:341-345
clientgoscheme.AddToSchemecan fail, and this helper currently drops that error. CouldnewSchemereturn(*runtime.Scheme, error)and wrap the failure close to the source so the control plane setup fails with clearer context?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/project/controlplane/controlplane.go` around lines 341 - 345, newScheme currently discards the error from clientgoscheme.AddToScheme, so update it to return (*runtime.Scheme, error) and propagate any failure instead of ignoring it. In the newScheme helper, check the AddToScheme result and wrap the error with clear context close to the source, then update the control plane setup call sites to handle the returned error from newScheme so initialization fails cleanly.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/project/controlplane/controlplane.go`:
- Around line 341-345: newScheme currently discards the error from
clientgoscheme.AddToScheme, so update it to return (*runtime.Scheme, error) and
propagate any failure instead of ignoring it. In the newScheme helper, check the
AddToScheme result and wrap the error with clear context close to the source,
then update the control plane setup call sites to handle the returned error from
newScheme so initialization fails cleanly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d7911130-09dc-45a1-85ee-c44d661c3521
📒 Files selected for processing (2)
internal/project/controlplane/controlplane.gointernal/schemas/manager/manager.go
Description of your changes
These two potential race conditions in project-related code were reported in
upbut are present here as well and could cause crashes due to concurrent map accesses:I have:
./nix.sh flake checkto ensure this PR is ready for review.- [ ] Added or updated unit tests.- [ ] Linked a PR or a docs tracking issue to document this change.backport release-x.ylabels to auto-backport this PR.