Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: concurrent map write panic #16081

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions upup/pkg/fi/cloudup/gce/gce_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/exec"
"strings"
"sync"

"golang.org/x/oauth2/google"
"google.golang.org/api/cloudresourcemanager/v1"
Expand Down Expand Up @@ -86,6 +87,7 @@ func (c *gceCloudImplementation) ProviderID() kops.CloudProviderID {
}

var gceCloudInstances map[string]GCECloud = make(map[string]GCECloud)
var gceCloudInstancesMapMutex = sync.RWMutex{}

// DefaultProject returns the current project configured in the gcloud SDK, ("", nil) if no project was set
func DefaultProject() (string, error) {
Expand Down Expand Up @@ -119,7 +121,9 @@ func DefaultProject() (string, error) {
}

func NewGCECloud(region string, project string, labels map[string]string) (GCECloud, error) {
gceCloudInstancesMapMutex.RLock()
i := gceCloudInstances[region+"::"+project]
gceCloudInstancesMapMutex.RUnlock()
if i != nil {
return i.(gceCloudInternal).WithLabels(labels), nil
}
Expand Down Expand Up @@ -179,6 +183,8 @@ func NewGCECloud(region string, project string, labels map[string]string) (GCECl
}

func CacheGCECloudInstance(region string, project string, c GCECloud) {
gceCloudInstancesMapMutex.Lock()
defer gceCloudInstancesMapMutex.Unlock()
gceCloudInstances[region+"::"+project] = c
}

Expand Down