diff --git a/rules/lock/lock.go b/rules/lock/lock.go index c9f6d8c..0526093 100644 --- a/rules/lock/lock.go +++ b/rules/lock/lock.go @@ -68,15 +68,18 @@ var ErrNilMutex = errors.New("mutex is nil") func (v3l *v3Lock) Unlock() error { if v3l.mutex != nil { - // TODO: Should the timeout for this be configurable too? Or use the same value as lock? - // It's a slightly different case in that here we want to make sure the unlock - // succeeds to free it for the use of others. In the lock case we want to give up - // early if someone already has the lock. - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5)*time.Second) + // This should be given every chance to complete, otherwise + // a lock could prevent future interactions with a resource. + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() err := v3l.mutex.Unlock(ctx) - if err == nil && v3l.session != nil { - v3l.session.Close() + // If the lock failed to be released, as least closing the session + // will allow the lease it is associated with to expire. + if v3l.session != nil { + serr := v3l.session.Close() + if err == nil { + err = serr + } } return err }