From 8d99b1309c57084371e6866c6f1ae0a682a8caaf Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 28 Aug 2023 17:36:00 +0200 Subject: [PATCH 1/3] Fix merge conflict with new tests This was merged while we also merged the context leak fixes, so now `main` is broken. This fixes it. Signed-off-by: Dirkjan Bussink --- go/vt/vtctl/grpcvtctldserver/server_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/go/vt/vtctl/grpcvtctldserver/server_test.go b/go/vt/vtctl/grpcvtctldserver/server_test.go index 96c8a763df0..947f8884064 100644 --- a/go/vt/vtctl/grpcvtctldserver/server_test.go +++ b/go/vt/vtctl/grpcvtctldserver/server_test.go @@ -1254,8 +1254,9 @@ func TestCancelSchemaMigration(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { - ctx := context.Background() - ts := memorytopo.NewServer("zone1") + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ts := memorytopo.NewServer(ctx, "zone1") testutil.AddTablets(ctx, t, ts, &testutil.AddTabletOptions{ AlsoSetShardPrimary: true, From aa9f7d376c168f2b9aae0e71c6a5a78b5578766b Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 28 Aug 2023 20:17:07 +0200 Subject: [PATCH 2/3] Also shut down goroutine on context expiry Signed-off-by: Dirkjan Bussink --- go/ioutil/timeout_closer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/go/ioutil/timeout_closer.go b/go/ioutil/timeout_closer.go index 0545d81cd00..1f025fbdb44 100644 --- a/go/ioutil/timeout_closer.go +++ b/go/ioutil/timeout_closer.go @@ -45,7 +45,10 @@ func (c *TimeoutCloser) Close() error { go func() { defer close(done) - done <- c.closer.Close() + select { + case done <- c.closer.Close(): + case <-ctx.Done(): + } }() select { case err := <-done: From 9963cefe582d2f8c1fb76f9494ce606c6c919080 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 28 Aug 2023 21:34:13 +0200 Subject: [PATCH 3/3] Avoid race condition for shutdown Signed-off-by: Dirkjan Bussink --- go/vt/srvtopo/resilient_server_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/go/vt/srvtopo/resilient_server_test.go b/go/vt/srvtopo/resilient_server_test.go index 1dfe0340fdf..c237d43f300 100644 --- a/go/vt/srvtopo/resilient_server_test.go +++ b/go/vt/srvtopo/resilient_server_test.go @@ -46,7 +46,6 @@ func TestGetSrvKeyspace(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ts, factory := memorytopo.NewServerAndFactory(ctx, "test_cell") - defer ts.Close() srvTopoCacheTTL = 200 * time.Millisecond srvTopoCacheRefresh = 80 * time.Millisecond defer func() { @@ -365,7 +364,6 @@ func TestSrvKeyspaceCachedError(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ts := memorytopo.NewServer(ctx, "test_cell") - defer ts.Close() srvTopoCacheTTL = 100 * time.Millisecond srvTopoCacheRefresh = 40 * time.Millisecond defer func() { @@ -437,7 +435,6 @@ func TestWatchSrvVSchema(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ts := memorytopo.NewServer(ctx, "test_cell") - defer ts.Close() rs := NewResilientServer(ctx, ts, "TestWatchSrvVSchema") // mu protects watchValue and watchErr. @@ -523,7 +520,6 @@ func TestGetSrvKeyspaceNames(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ts, factory := memorytopo.NewServerAndFactory(ctx, "test_cell") - defer ts.Close() time.Sleep(1 * time.Second) @@ -682,7 +678,6 @@ func TestSrvKeyspaceWatcher(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ts, factory := memorytopo.NewServerAndFactory(ctx, "test_cell") - defer ts.Close() srvTopoCacheTTL = 100 * time.Millisecond srvTopoCacheRefresh = 40 * time.Millisecond defer func() { @@ -809,7 +804,6 @@ func TestSrvKeyspaceListener(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ts := memorytopo.NewServer(ctx, "test_cell") - defer ts.Close() srvTopoCacheTTL = 100 * time.Millisecond srvTopoCacheRefresh = 40 * time.Millisecond defer func() {