fix: protect RepositoryTimesForMetrics from concurrent map access#314
fix: protect RepositoryTimesForMetrics from concurrent map access#314MartinBasti wants to merge 1 commit into
Conversation
The global map was read/written/deleted from multiple reconciler goroutines without synchronization, which can cause a fatal panic. Replace the exported map with mutex-protected helper functions. Signed-off-by: Martin Basti <mbasti@redhat.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Martin Basti <mbasti@redhat.com>
Review Summary by QodoProtect RepositoryTimesForMetrics from concurrent map access
WalkthroughsDescription• Replace exported map with mutex-protected helper functions • Prevent concurrent map access race condition in metrics • Add three new thread-safe accessor functions for map operations • Include comprehensive unit tests for concurrency safety Diagramflowchart LR
A["Exported map<br/>RepositoryTimesForMetrics"] -->|"Replace with"| B["Private map +<br/>sync.Mutex"]
B -->|"Provide access via"| C["SetRepositoryTimeIfAbsent"]
B -->|"Provide access via"| D["GetRepositoryTime"]
B -->|"Provide access via"| E["DeleteRepositoryTime"]
C -->|"Used by"| F["imagerepository_controller.go"]
D -->|"Used by"| F
E -->|"Used by"| F
File Changes1. pkg/metrics/metrics.go
|
Code Review by Qodo
1. Serialized metric reads
|
|
More context from AI |
|
Scenario: konflux-e2e-image-controller
Inspecting Test ArtifactsTo inspect your test artifacts, follow these steps:
mkdir -p oras-artifacts
cd oras-artifacts
oras pull quay.io/konflux-test-storage/konflux-team/image-controller:konflux-e2e-image-controller-n725nTest results analysis🚨 Error occurred while running the E2E tests, list of failed Spec(s): ➡️ [ Click to view logsUnexpected error:
<*errors.errorString | 0xc0003f36b0>:
failed to create test namespace build-e2e-nozh: timeout waiting for service account konflux-integration-runner to be created in namespace build-e2e-nozh with error: context deadline exceeded
{
s: "failed to create test namespace build-e2e-nozh: timeout waiting for service account konflux-integration-runner to be created in namespace build-e2e-nozh with error: context deadline exceeded",
}
occurredOCI Artifact Browser URL |
The global map was read/written/deleted from multiple reconciler goroutines without synchronization, which can cause a fatal panic. Replace the exported map with mutex-protected helper functions.