Sfoglia il codice sorgente

Fix a race in libcontainerd/pausemonitor_linux.go

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Akihiro Suda 8 anni fa
parent
commit
69f00a137c
1 ha cambiato i file con 9 aggiunte e 0 eliminazioni
  1. 9 0
      libcontainerd/pausemonitor_linux.go

+ 9 - 0
libcontainerd/pausemonitor_linux.go

@@ -1,11 +1,18 @@
 package libcontainerd
 package libcontainerd
 
 
+import (
+	"sync"
+)
+
 // pauseMonitor is helper to get notifications from pause state changes.
 // pauseMonitor is helper to get notifications from pause state changes.
 type pauseMonitor struct {
 type pauseMonitor struct {
+	sync.Mutex
 	waiters map[string][]chan struct{}
 	waiters map[string][]chan struct{}
 }
 }
 
 
 func (m *pauseMonitor) handle(t string) {
 func (m *pauseMonitor) handle(t string) {
+	m.Lock()
+	defer m.Unlock()
 	if m.waiters == nil {
 	if m.waiters == nil {
 		return
 		return
 	}
 	}
@@ -20,6 +27,8 @@ func (m *pauseMonitor) handle(t string) {
 }
 }
 
 
 func (m *pauseMonitor) append(t string, waiter chan struct{}) {
 func (m *pauseMonitor) append(t string, waiter chan struct{}) {
+	m.Lock()
+	defer m.Unlock()
 	if m.waiters == nil {
 	if m.waiters == nil {
 		m.waiters = make(map[string][]chan struct{})
 		m.waiters = make(map[string][]chan struct{})
 	}
 	}