Skip to content

Commit

Permalink
rpc: Handle closed error
Browse files Browse the repository at this point in the history
We close the listener before closing the connection. This can result in
a spurious failure due to the Listener also closing our connection.

Epic: none
Fixes: #100391
Fixes: #77754
Informs: #80034

Release note: None
  • Loading branch information
andrewbaptist committed Apr 3, 2023
1 parent 91c7269 commit be4b1d3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/rpc/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,9 @@ func TestHeartbeatHealthTransport(t *testing.T) {
defer mu.Unlock()
n := len(mu.conns)
for i := n - 1; i >= 0; i-- {
if err := mu.conns[i].Close(); err != nil {
// This can spuriously return ErrClosed since the listener is closed
// before us.
if err := mu.conns[i].Close(); err != nil && !errors.Is(err, net.ErrClosed) {
return 0, err
}
mu.conns = mu.conns[:i]
Expand Down Expand Up @@ -1272,10 +1274,16 @@ func TestHeartbeatHealthTransport(t *testing.T) {
return nil
})

// TODO(baptist): Better understand when this happens. It appears we can get
// spurious connections to other tests on a stress run. This has been
// happening for a while, but only comes out rarely when this package is
// stressed. This test is very aggressive since it is calling GRPCDialNode in
// a busy loop for 50ms.
expected := "doesn't match server cluster ID"
// Should stay unhealthy despite reconnection attempts.
for then := timeutil.Now(); timeutil.Since(then) < 50*clientCtx.Config.RPCHeartbeatTimeout; {
err := clientCtx.TestingConnHealth(remoteAddr, serverNodeID)
if !isUnhealthy(err) {
if !isUnhealthy(err) && !testutils.IsError(err, expected) {
t.Fatal(err)
}
}
Expand Down

0 comments on commit be4b1d3

Please sign in to comment.