Skip to content

Commit

Permalink
feat: add a test and fix the segmentation fault
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Apr 18, 2024
1 parent 64d9037 commit 632b3d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions go/vt/vttablet/grpctmclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions go/vt/vttablet/grpctmclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 632b3d9

Please sign in to comment.