From 632b3d9190706af6af1aa349e2f7c32fb193fdf8 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 18 Apr 2024 21:29:06 +0530 Subject: [PATCH] feat: add a test and fix the segmentation fault Signed-off-by: Manan Gupta --- go/vt/vttablet/grpctmclient/client.go | 6 ++++-- go/vt/vttablet/grpctmclient/client_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/go/vt/vttablet/grpctmclient/client.go b/go/vt/vttablet/grpctmclient/client.go index dac6c7e0822..7f1b63906ec 100644 --- a/go/vt/vttablet/grpctmclient/client.go +++ b/go/vt/vttablet/grpctmclient/client.go @@ -235,8 +235,10 @@ func (client *grpcClient) dialDedicatedPool(ctx context.Context, dialPoolGroup D invalidator := func() { client.mu.Lock() defer client.mu.Unlock() - m[addr].cc.Close() - delete(m, addr) + if _, exists := m[addr]; exists { + m[addr].cc.Close() + delete(m, addr) + } } return m[addr].client, invalidator, nil } diff --git a/go/vt/vttablet/grpctmclient/client_test.go b/go/vt/vttablet/grpctmclient/client_test.go index f842b216d8c..1487303163d 100644 --- a/go/vt/vttablet/grpctmclient/client_test.go +++ b/go/vt/vttablet/grpctmclient/client_test.go @@ -48,6 +48,13 @@ func TestDialDedicatedPool(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, invalidator) assert.NotNil(t, cli) + _, invalidatorTwo, err := poolDialer.dialDedicatedPool(ctx, dialPoolGroupThrottler, tablet) + assert.NoError(t, err) + // Ensure that running both the invalidators doesn't cause any issues. + invalidator() + invalidatorTwo() + _, _, err = poolDialer.dialDedicatedPool(ctx, dialPoolGroupThrottler, tablet) + assert.NoError(t, err) }) var cachedTmc *tmc