From cde92fd4b30319275437c0869c5324688eae8e15 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 26 Oct 2023 16:51:47 -0400 Subject: [PATCH] fix: bigtable-rotator bug that prevents it from closing channels --- .../btrefresh/bigtable_rotator.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/go/connection-refresh/btrefresh/bigtable_rotator.go b/go/connection-refresh/btrefresh/bigtable_rotator.go index 4ff9234a..d2c8f3e7 100644 --- a/go/connection-refresh/btrefresh/bigtable_rotator.go +++ b/go/connection-refresh/btrefresh/bigtable_rotator.go @@ -61,12 +61,9 @@ func NewRotatingTable(dialer BtDialer, table string, refresh time.Duration) (*Ro rt := &RotatingTable{tbl, client, ticker, errors} go func() { for range ticker.C { - // Close the old client after waiting a bit - go func() { - oldC := rt.client - time.Sleep(lameduckTime) - oldC.Close() - }() + // save the old client so that we can close it + oldC := rt.client + client, err := dialer() if err != nil { errors <- err @@ -74,7 +71,15 @@ func NewRotatingTable(dialer BtDialer, table string, refresh time.Duration) (*Ro } tbl := client.Open(table) warmTable(tbl) + + rt.client = client rt.Table = tbl + + // Close the old client after waiting a bit + go func() { + time.Sleep(lameduckTime) + oldC.Close() + }() } }() return rt, nil