From 5d5f954cd1847505ce6377fdeac9603cb64d9e99 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Sep 2022 14:26:23 +0800 Subject: [PATCH] etcd: try put again when the ch closed --- etcd.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/etcd.go b/etcd.go index 2adc7d4..ea7fc2f 100644 --- a/etcd.go +++ b/etcd.go @@ -131,6 +131,21 @@ func (s *Store) Put(ctx context.Context, key string, value []byte, opts *store.W for v := range ch { _ = v } + + // try put again when the ch closed + for { + select { + case <-s.client.Ctx().Done(): + return + default: + err = s.Put(context.Background(), key, value, opts) + if err != nil { + time.Sleep(time.Second) + continue + } + return + } + } }() }