Skip to content

Commit c05b767

Browse files
authored
fix(bigtable/internal/transport): drop redundant defer p.Close() in AFE picker tests (#20311)
## Summary Four AFE picker tests in `session_pool_afe_test.go` each declared `defer p.Close()` on a pool returned by `newTestPool`. That defer runs **before** the `t.Cleanup` registered by `newTestPool`, which is `closeStreams(); _ = p.Close()`. When `Tick` fires during the checkout loop and spawns a fresh session via the stub factory, the new session's readLoop parks on `fakeStream.Recv`. The test-body defer then calls `p.Close()`, which waits on `p.spawns` for the `createSession` goroutine, which waits on `Session.WaitGoroutines` for the readLoop — but the readLoop only exits when `closeStreams` closes the recv channel, and `closeStreams` is inside the `t.Cleanup` that hasn't run yet. Deadlock; test hangs to timeout. `newTestPool`'s `t.Cleanup` already runs `closeStreams` first, then `Close`, in the correct order — the per-test `defer p.Close()` was redundant and actively wrong. Dropping it fixes the deadlock. Fixes #20308. ## Test plan - [x] Reproduced the hang: `go test -run '^TestPool_LeastInFlight_FansOutAcrossAFEs$' -count=50 -race -timeout=45s` — passes iters 1–3, hangs on iter 4 with goroutine dump showing `defer p.Close()` → `p.spawns.Wait()` → stuck on `Session.WaitGoroutines` → stuck on `fakeStream.Recv`. - [x] Verified fix: same command with `-count=200 -race -timeout=90s` — passes in ~3s. - [x] `go test -count=1 -timeout=60s ./bigtable/internal/transport/...` — full transport suite green.
1 parent 5c49ac3 commit c05b767

1 file changed

Lines changed: 0 additions & 4 deletions

File tree

‎bigtable/internal/transport/session_pool_afe_test.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ func checkoutAndRelease(t *testing.T, p *SessionPoolImpl, recordLatency time.Dur
7474
// every AFE has the same number of idle sessions.
7575
func TestPool_LeastInFlight_FansOutAcrossAFEs(t *testing.T) {
7676
p := newTestPool(t, 1, 30)
77-
defer p.Close()
7877

7978
// 3 AFEs × 2 sessions each = 6 sessions total.
8079
afes := []AfeID{101, 202, 303}
@@ -104,7 +103,6 @@ func TestPool_LeastInFlight_FansOutAcrossAFEs(t *testing.T) {
104103
// with a much lower latency history.
105104
func TestPool_LeastLatency_PrefersLowCostAFE(t *testing.T) {
106105
p := newTestPool(t, 1, 20)
107-
defer p.Close()
108106

109107
// Switch picker to LeastLatency (subset-size = 2 = both AFEs).
110108
p.picker = NewLeastLatencyAfePicker(2, true)
@@ -142,7 +140,6 @@ func TestPool_LeastLatency_PrefersLowCostAFE(t *testing.T) {
142140
// (SessionList.java:181-187).
143141
func TestPool_LeastLatency_IgnoresFailingAFELatency(t *testing.T) {
144142
p := newTestPool(t, 1, 20)
145-
defer p.Close()
146143

147144
p.picker = NewLeastLatencyAfePicker(2, true)
148145

@@ -191,7 +188,6 @@ func TestPool_LeastLatency_IgnoresFailingAFELatency(t *testing.T) {
191188
// sessions still get picked, just from the shared unknown bucket.
192189
func TestPool_UnknownAFE_BucketedAtZero(t *testing.T) {
193190
p := newTestPool(t, 1, 20)
194-
defer p.Close()
195191

196192
// injectActiveSession (no On-Afe variant) — leaves PeerInfo nil so
197193
// AfeID() returns 0.

0 commit comments

Comments
 (0)