resources: fix deadlock on recursion

This was a sneaky deadlock which wasn't 100% reproducible. It was pretty
tricky to find because the same deadlocked behaviour was seen due to the
regression in the fsnotify module.

The event system needs a bit of a cleaning, but this can happen later.
This commit is contained in:
James Shubin
2016-10-01 08:19:46 -04:00
parent 9368c7e05f
commit 567dcaf79d

View File

@@ -242,22 +242,24 @@ func (obj *BaseRes) SetState(state ResState) {
func (obj *BaseRes) DoSend(processChan chan event.Event, comment string) (bool, error) { func (obj *BaseRes) DoSend(processChan chan event.Event, comment string) (bool, error) {
resp := event.NewResp() resp := event.NewResp()
processChan <- event.Event{event.EventNil, resp, comment, true} // trigger process processChan <- event.Event{event.EventNil, resp, comment, true} // trigger process
select { e := resp.Wait()
case e := <-resp: // wait for the ACK() return false, e // XXX: at the moment, we don't use the exit bool.
if e != nil { // we got a NACK // XXX: this can cause a deadlock. do we need to recursively send? fix event stuff!
return true, e // exit with error //select {
} //case e := <-resp: // wait for the ACK()
// if e != nil { // we got a NACK
case event := <-obj.events: // return true, e // exit with error
// NOTE: this code should match the similar code below! // }
//cuuid.SetConverged(false) // TODO ? //case event := <-obj.events:
if exit, send := obj.ReadEvent(&event); exit { // // NOTE: this code should match the similar code below!
return true, nil // exit, without error // //cuuid.SetConverged(false) // TODO ?
} else if send { // if exit, send := obj.ReadEvent(&event); exit {
return obj.DoSend(processChan, comment) // recurse // return true, nil // exit, without error
} // } else if send {
} // return obj.DoSend(processChan, comment) // recurse
return false, nil // return, no error or exit signal // }
//}
//return false, nil // return, no error or exit signal
} }
// SendEvent pushes an event into the message queue for a particular vertex // SendEvent pushes an event into the message queue for a particular vertex