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 {
204204 }
205205
206206 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.
207209 s .mu .Lock ()
208- defer s .mu .Unlock ()
209210
210211 // Un-allocated task.
211212 if t .NodeID == "" {
212213 s .pendingTasks [t .ID ] = struct {}{}
214+ s .mu .Unlock ()
213215 return
214216 }
215217
216218 delete (s .pendingTasks , t .ID )
217219 if _ , ok := s .nodes [t .NodeID ]; ! ok {
218220 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.
219227 s .changed .Publish (s )
228+ return
220229 }
230+
231+ s .mu .Unlock ()
221232 }
222233
223234 for {
You can’t perform that action at this time.
0 commit comments