Skip to content

Commit ee5cbce

Browse files
authored
ringhash: fix bug where ring hash can be stuck in transient failure despite having available endpoints (#7364)
1 parent 1e2bb71 commit ee5cbce

File tree

5 files changed

+490
-42
lines changed

5 files changed

+490
-42
lines changed

internal/testutils/blocking_context_dialer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,13 @@ func (h *Hold) Fail(err error) {
127127
h.blockCh <- err
128128
close(h.blockCh)
129129
}
130+
131+
// IsStarted returns true if this hold has received a connection attempt.
132+
func (h *Hold) IsStarted() bool {
133+
select {
134+
case <-h.waitCh:
135+
return true
136+
default:
137+
return false
138+
}
139+
}

internal/testutils/blocking_context_dialer_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
5959
d := NewBlockingDialer()
6060
h := d.Hold(lis.Addr().String())
6161

62+
if h.IsStarted() {
63+
t.Fatalf("hold.IsStarted() = true, want false")
64+
}
65+
6266
done := make(chan struct{})
6367
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
6468
defer cancel()
@@ -69,13 +73,22 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
6973
t.Errorf("BlockingDialer.DialContext() got error: %v, want success", err)
7074
return
7175
}
76+
77+
if !h.IsStarted() {
78+
t.Errorf("hold.IsStarted() = false, want true")
79+
}
7280
conn.Close()
7381
}()
7482

7583
// This should block until the goroutine above is scheduled.
7684
if !h.Wait(ctx) {
7785
t.Fatalf("Timeout while waiting for a connection attempt to %q", h.addr)
7886
}
87+
88+
if !h.IsStarted() {
89+
t.Errorf("hold.IsStarted() = false, want true")
90+
}
91+
7992
select {
8093
case <-done:
8194
t.Fatalf("Expected dialer to be blocked.")

0 commit comments

Comments
 (0)