diff --git a/plugins/sync/etcd/etcd.go b/plugins/sync/etcd/etcd.go index 05a4210b..978ee090 100644 --- a/plugins/sync/etcd/etcd.go +++ b/plugins/sync/etcd/etcd.go @@ -115,7 +115,15 @@ func (e *etcdSync) Lock(id string, opts ...sync.LockOption) error { m := cc.NewMutex(s, path) - if err := m.Lock(context.TODO()); err != nil { + lockCtx := context.Background() + if options.Wait > 0 { + var cancel context.CancelFunc + lockCtx, cancel = context.WithTimeout(lockCtx, options.Wait) + defer cancel() + } + if err := m.Lock(lockCtx); err != nil && err == context.DeadlineExceeded { + return sync.ErrLockTimeout + } else if err != nil { return err }