From 0637e200775ffa14a344854a9f4d77e0147b8f61 Mon Sep 17 00:00:00 2001 From: Edoardo Spadolini Date: Tue, 30 Jul 2024 16:04:34 +0200 Subject: [PATCH] Fix rare TestResumption deadlock --- lib/resumption/client.go | 10 ++++++---- lib/resumption/resumption_test.go | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/resumption/client.go b/lib/resumption/client.go index f12f51a35805f..3325a3b74e7f4 100644 --- a/lib/resumption/client.go +++ b/lib/resumption/client.go @@ -219,6 +219,12 @@ func runClientResumableUnlocking(ctx context.Context, resumableConn *Conn, first case <-detached: } + reconnectTicker.Stop() + select { + case <-reconnectTicker.Chan(): + default: + } + slog.DebugContext(ctx, "connection lost, starting reconnection loop", "host_id", hostID) reconnectDeadline := time.Now().Add(reconnectTimeout) backoff := minBackoff @@ -262,10 +268,6 @@ func runClientResumableUnlocking(ctx context.Context, resumableConn *Conn, first } reconnectTicker.Reset(replacementInterval) - select { - case <-reconnectTicker.Chan(): - default: - } } } diff --git a/lib/resumption/resumption_test.go b/lib/resumption/resumption_test.go index de6f74a89f58c..db915fcb062f3 100644 --- a/lib/resumption/resumption_test.go +++ b/lib/resumption/resumption_test.go @@ -212,6 +212,9 @@ func testResumption(t *testing.T, network, address string, expectedHostID string default: } + // wait until the reconnection loop has passed the reconnection phase + // and is waiting on the reconnection timer again + clock.BlockUntil(1) clock.Advance(replacementInterval) redialingSyncPoint <- struct{}{}