Skip to content

Commit

Permalink
Reduce locking contention for cron dist mutex reuse.
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
  • Loading branch information
artursouza committed Mar 13, 2024
1 parent 28e055b commit 496f658
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ func (c *Cron) run(ctx context.Context) {
return
}

localMutexer.Lock(tickLock)
defer localMutexer.Unlock(tickLock)

lockCtx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()

// Local mutex is needed to avoid race condition on reusing the etcd mutex object.
localMutexer.Lock(tickLock)
err = m.Lock(lockCtx)
localMutexer.Unlock(tickLock)
if err == context.DeadlineExceeded {
return
} else if err != nil {
Expand Down

0 comments on commit 496f658

Please sign in to comment.