From 61565fa18cb8ab2c6e17a9e08c38f4dca57b20ac Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sun, 19 Nov 2023 00:28:08 -0700 Subject: [PATCH] Made lockable abort fully if everything unlocked on first error --- lockable.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lockable.go b/lockable.go index 5957999..25c8a96 100644 --- a/lockable.go +++ b/lockable.go @@ -105,17 +105,30 @@ func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeI } case Locking: changes.Add(LockableExtType, "state") - ext.State = AbortingLock ext.Requirements[info.Destination] = Unlocked - for id, state := range(ext.Requirements) { - if state == Locked { - ext.Requirements[id] = Unlocking - lock_signal := NewLockSignal("unlock") - ext.WaitInfos[lock_signal.Id] = node.QueueTimeout("unlock", id, lock_signal, 100*time.Millisecond) - messages = messages.Add(ctx, id, node, nil, lock_signal) - ctx.Log.Logf("lockable", "sent abort unlock to %s from %s", id, node.ID) + unlocked := 0 + for _, state := range(ext.Requirements) { + if state == Unlocked { + unlocked += 1 } } + + if unlocked == len(ext.Requirements) { + ctx.Log.Logf("lockable", "%s unlocked from error %s from %s", node.ID, signal.Error, source) + ext.State = Unlocked + } else { + ext.State = AbortingLock + for id, state := range(ext.Requirements) { + if state == Locked { + ext.Requirements[id] = Unlocking + lock_signal := NewLockSignal("unlock") + ext.WaitInfos[lock_signal.Id] = node.QueueTimeout("unlock", id, lock_signal, 100*time.Millisecond) + messages = messages.Add(ctx, id, node, nil, lock_signal) + ctx.Log.Logf("lockable", "sent abort unlock to %s from %s", id, node.ID) + } + } + } + case Unlocking: ext.Requirements[info.Destination] = Locked all_returned := true