From f4039b28ca8d54a3af3020742315b1246acf281b Mon Sep 17 00:00:00 2001 From: richie Date: Thu, 21 Sep 2017 11:52:29 +0800 Subject: [PATCH] do not wait lock when network broken --- store/etcd/etcd.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index c932ca66..263fce7c 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -485,12 +485,11 @@ func (l *etcdLock) Lock(stopChan chan struct{}) (<-chan struct{}, error) { setOpts.PrevExist = etcd.PrevNoExist resp, err := l.client.Set(context.Background(), l.key, l.value, setOpts) if err != nil { - if etcdError, ok := err.(etcd.Error); ok { - if etcdError.Code != etcd.ErrorCodeNodeExist { - return nil, err - } - setOpts.PrevIndex = ^uint64(0) + etcdError, ok := err.(etcd.Error) + if !ok || etcdError.Code != etcd.ErrorCodeNodeExist { + return nil, err } + setOpts.PrevIndex = ^uint64(0) } else { setOpts.PrevIndex = resp.Node.ModifiedIndex } @@ -505,10 +504,9 @@ func (l *etcdLock) Lock(stopChan chan struct{}) (<-chan struct{}, error) { break } else { // If this is a legitimate error, return - if etcdError, ok := err.(etcd.Error); ok { - if etcdError.Code != etcd.ErrorCodeTestFailed { - return nil, err - } + etcdError, ok := err.(etcd.Error) + if !ok || etcdError.Code != etcd.ErrorCodeNodeExist { + return nil, err } // Seeker section