Skip to content

Commit ca22d07

Browse files
BurtonQinfjl
andauthored
event: fix inconsistency in Lock and Unlock (#20933)
Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent 7a63faf commit ca22d07

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎event/event.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,19 @@ func (mux *TypeMux) Post(ev interface{}) error {
104104
// Stop blocks until all current deliveries have finished.
105105
func (mux *TypeMux) Stop() {
106106
mux.mutex.Lock()
107+
defer mux.mutex.Unlock()
107108
for _, subs := range mux.subm {
108109
for _, sub := range subs {
109110
sub.closewait()
110111
}
111112
}
112113
mux.subm = nil
113114
mux.stopped = true
114-
mux.mutex.Unlock()
115115
}
116116

117117
func (mux *TypeMux) del(s *TypeMuxSubscription) {
118118
mux.mutex.Lock()
119+
defer mux.mutex.Unlock()
119120
for typ, subs := range mux.subm {
120121
if pos := find(subs, s); pos >= 0 {
121122
if len(subs) == 1 {
@@ -125,7 +126,6 @@ func (mux *TypeMux) del(s *TypeMuxSubscription) {
125126
}
126127
}
127128
}
128-
s.mux.mutex.Unlock()
129129
}
130130

131131
func find(slice []*TypeMuxSubscription, item *TypeMuxSubscription) int {

0 commit comments

Comments
 (0)