From 475df52a1912d37b5408a66813ddd162612bac05 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 11 Sep 2019 18:54:25 -0700 Subject: [PATCH] Fix etcd watch regression in IAM subsystem (#8224) Fixes #8223 --- cmd/iam-etcd-store.go | 45 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/cmd/iam-etcd-store.go b/cmd/iam-etcd-store.go index bd253c016..9deadd2ac 100644 --- a/cmd/iam-etcd-store.go +++ b/cmd/iam-etcd-store.go @@ -503,28 +503,35 @@ func (ies *IAMEtcdStore) deleteGroupInfo(name string) error { func (ies *IAMEtcdStore) watch(sys *IAMSys) { watchEtcd := func() { - // Refresh IAMSys with etcd watch. for { + outerLoop: + // Refresh IAMSys with etcd watch. watchCh := ies.client.Watch(context.Background(), iamConfigPrefix, etcd.WithPrefix(), etcd.WithKeysOnly()) - select { - case <-GlobalServiceDoneCh: - return - case watchResp, ok := <-watchCh: - if !ok { - time.Sleep(1 * time.Second) - continue - } - if err := watchResp.Err(); err != nil { - logger.LogIf(context.Background(), err) - // log and retry. - time.Sleep(1 * time.Second) - continue - } - for _, event := range watchResp.Events { - sys.Lock() - ies.reloadFromEvent(sys, event) - sys.Unlock() + for { + select { + case <-GlobalServiceDoneCh: + return + case watchResp, ok := <-watchCh: + if !ok { + time.Sleep(1 * time.Second) + // Upon an error on watch channel + // re-init the watch channel. + goto outerLoop + } + if err := watchResp.Err(); err != nil { + logger.LogIf(context.Background(), err) + // log and retry. + time.Sleep(1 * time.Second) + // Upon an error on watch channel + // re-init the watch channel. + goto outerLoop + } + for _, event := range watchResp.Events { + sys.Lock() + ies.reloadFromEvent(sys, event) + sys.Unlock() + } } } }