Skip to content

Commit

Permalink
Fix concurrent map write crash in logIfChanged
Browse files Browse the repository at this point in the history
The loggedImages map needs to be synchronized.

Fixes submariner-io/submariner#2872

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Jan 10, 2024
1 parent e934610 commit bf364d9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"strings"
"sync"

apis "github.com/submariner-io/submariner-operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -60,7 +61,7 @@ type imageParameters struct {

var (
log = logf.Log.WithName("images")
loggedImages = make(map[imageParameters]string)
loggedImages = sync.Map{}
)

func logIfChanged(repo, version, image, component, result, explanation string) string {
Expand All @@ -70,15 +71,13 @@ func logIfChanged(repo, version, image, component, result, explanation string) s
image: image,
component: component,
}
previous, ok := loggedImages[imageParams]

previous, ok := loggedImages.Swap(imageParams, result)
if !ok || result != previous {
log.Info("New GetImagePath result", "repo", repo, "version", version, "image", image, "component", component,
"previous", previous, "result", result, "explanation", explanation)
}

loggedImages[imageParams] = result

return result
}

Expand Down

0 comments on commit bf364d9

Please sign in to comment.