Skip to content

Commit 77c556b

Browse files
committed
fix: guard ContainerManager.active map with a mutex
ContainerManager.active is a plain map accessed from the goroutine in Start (via checkPod) without synchronisation. Under concurrent pod events this causes a fatal "concurrent map read and map write" crash. Add a sync.Mutex and lock it around the map access in checkPod. Fixes #9081 Signed-off-by: alliasgher <alliasgher123@gmail.com>
1 parent d1b2d1c commit 77c556b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pkg/skaffold/kubernetes/debugging/container_manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package debugging
1919
import (
2020
"context"
2121
"encoding/json"
22+
"sync"
2223

2324
v1 "k8s.io/api/core/v1"
2425
"k8s.io/apimachinery/pkg/watch"
@@ -39,8 +40,11 @@ var (
3940
)
4041

4142
type ContainerManager struct {
42-
podWatcher kubernetes.PodWatcher
43-
active map[string]string // set of containers that have been notified
43+
podWatcher kubernetes.PodWatcher
44+
45+
mu sync.Mutex
46+
active map[string]string // set of containers that have been notified
47+
4448
events chan kubernetes.PodEvent
4549
stopWatcher func()
4650
namespaces *[]string
@@ -117,6 +121,8 @@ func (d *ContainerManager) checkPod(evtType watch.EventType, pod *v1.Pod) {
117121
log.Entry(context.TODO()).Warnf("Unable to parse debug-config for pod %s/%s: '%s'", pod.Namespace, pod.Name, debugConfigString)
118122
return
119123
}
124+
d.mu.Lock()
125+
defer d.mu.Unlock()
120126
for _, c := range pod.Status.ContainerStatuses {
121127
// only examine debuggable containers
122128
if config, found := configurations[c.Name]; found {

0 commit comments

Comments
 (0)