File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -204,20 +204,31 @@ func (s *subscription) watch(ch <-chan events.Event) error {
204
204
}
205
205
206
206
add := func (t * api.Task ) {
207
+ // this mutex does not have a deferred unlock, because there is work
208
+ // we need to do after we release it.
207
209
s .mu .Lock ()
208
- defer s .mu .Unlock ()
209
210
210
211
// Un-allocated task.
211
212
if t .NodeID == "" {
212
213
s .pendingTasks [t .ID ] = struct {}{}
214
+ s .mu .Unlock ()
213
215
return
214
216
}
215
217
216
218
delete (s .pendingTasks , t .ID )
217
219
if _ , ok := s .nodes [t .NodeID ]; ! ok {
218
220
s .nodes [t .NodeID ] = struct {}{}
221
+
222
+ s .mu .Unlock ()
223
+
224
+ // if we try to call Publish before we release the lock, we can end
225
+ // up in a situation where the receiver is trying to acquire a read
226
+ // lock on it. it's hard to explain.
219
227
s .changed .Publish (s )
228
+ return
220
229
}
230
+
231
+ s .mu .Unlock ()
221
232
}
222
233
223
234
for {
You can’t perform that action at this time.
0 commit comments