Skip to content

Commit

Permalink
Change session close logic (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jswarren4 authored Oct 28, 2021
1 parent 0285143 commit e8aab7a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions rules/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e8aab7a

Please sign in to comment.