5
5
"os"
6
6
"path"
7
7
"strings"
8
+ "sync"
8
9
9
10
log "github.com/sirupsen/logrus"
10
11
)
@@ -48,12 +49,15 @@ func SetupUnixSocketNotifier(notifiers map[string]chan Message, exits map[string
48
49
notifiers ["notifier/unix_socket" ] = touch
49
50
50
51
touchListeners := make (map [* net.Conn ]chan []byte )
52
+ touchListenersMutex := sync.RWMutex {}
51
53
go func () {
52
54
for {
53
55
value := <- touch
56
+ touchListenersMutex .RLock ()
54
57
for _ , listener := range touchListeners {
55
58
listener <- []byte (value )
56
59
}
60
+ touchListenersMutex .RUnlock ()
57
61
}
58
62
}()
59
63
@@ -66,15 +70,19 @@ func SetupUnixSocketNotifier(notifiers map[string]chan Message, exits map[string
66
70
return
67
71
}
68
72
69
- go notify (listener , touchListeners )
73
+ go notify (listener , touchListeners , & touchListenersMutex )
70
74
}
71
75
}
72
76
73
- func notify (listener net.Conn , touchListeners map [* net.Conn ]chan []byte ) {
77
+ func notify (listener net.Conn , touchListeners map [* net.Conn ]chan []byte , touchListenersMutex * sync. RWMutex ) {
74
78
values := make (chan []byte )
79
+ touchListenersMutex .Lock ()
75
80
touchListeners [& listener ] = values
81
+ touchListenersMutex .Unlock ()
76
82
defer (func () {
83
+ touchListenersMutex .Lock ()
77
84
delete (touchListeners , & listener )
85
+ touchListenersMutex .Unlock ()
78
86
listener .Close ()
79
87
})()
80
88
0 commit comments