Fix etcd watch regression in IAM subsystem (#8224)

Fixes #8223
This commit is contained in:
Harshavardhana 2019-09-11 18:54:25 -07:00 committed by kannappanr
parent 5512baab21
commit 475df52a19

View File

@ -503,23 +503,29 @@ func (ies *IAMEtcdStore) deleteGroupInfo(name string) error {
func (ies *IAMEtcdStore) watch(sys *IAMSys) { func (ies *IAMEtcdStore) watch(sys *IAMSys) {
watchEtcd := func() { watchEtcd := func() {
// Refresh IAMSys with etcd watch.
for { for {
outerLoop:
// Refresh IAMSys with etcd watch.
watchCh := ies.client.Watch(context.Background(), watchCh := ies.client.Watch(context.Background(),
iamConfigPrefix, etcd.WithPrefix(), etcd.WithKeysOnly()) iamConfigPrefix, etcd.WithPrefix(), etcd.WithKeysOnly())
for {
select { select {
case <-GlobalServiceDoneCh: case <-GlobalServiceDoneCh:
return return
case watchResp, ok := <-watchCh: case watchResp, ok := <-watchCh:
if !ok { if !ok {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
continue // Upon an error on watch channel
// re-init the watch channel.
goto outerLoop
} }
if err := watchResp.Err(); err != nil { if err := watchResp.Err(); err != nil {
logger.LogIf(context.Background(), err) logger.LogIf(context.Background(), err)
// log and retry. // log and retry.
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
continue // Upon an error on watch channel
// re-init the watch channel.
goto outerLoop
} }
for _, event := range watchResp.Events { for _, event := range watchResp.Events {
sys.Lock() sys.Lock()
@ -529,6 +535,7 @@ func (ies *IAMEtcdStore) watch(sys *IAMSys) {
} }
} }
} }
}
go watchEtcd() go watchEtcd()
} }