Skip to content

Commit

Permalink
GRPC: Address potential segfault in dedicated connection pooling (#15751
Browse files Browse the repository at this point in the history
)

Signed-off-by: Manan Gupta <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
Co-authored-by: Shlomi Noach <[email protected]>
Co-authored-by: Matt Lord <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent 008e02a commit ff6ca02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions go/vt/vttablet/grpctmclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ 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 tm, ok := m[addr]; ok {
if tm != nil && tm.cc != nil {
tm.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 ff6ca02

Please sign in to comment.