From 06e396188f42cc03fbb85574441f8eead5998a63 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Thu, 29 Jan 2026 13:34:34 +0400 Subject: [PATCH] test: subscribe to heartbeats synchronously on PGCoord startup (#21746) fixes: https://github.com/coder/internal/issues/1304 Subscribe to heartbeats synchronously on startup of PGCoordinator. This ensures tests that send heartbeats don't race with this subscription. --- enterprise/tailnet/pgcoord.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/enterprise/tailnet/pgcoord.go b/enterprise/tailnet/pgcoord.go index 892ddc5c72..2bb1e30711 100644 --- a/enterprise/tailnet/pgcoord.go +++ b/enterprise/tailnet/pgcoord.go @@ -1509,7 +1509,7 @@ func newHeartbeats( clock: clk, } h.wg.Add(3) - go h.subscribe() + h.subscribe() go h.sendBeats() go h.cleanupLoop() return h @@ -1560,9 +1560,11 @@ func (h *heartbeats) subscribe() { } return } - // cancel subscription when context finishes - defer cancel() - <-h.ctx.Done() + go func() { + // cancel subscription when context finishes + <-h.ctx.Done() + cancel() + }() } func (h *heartbeats) listen(_ context.Context, msg []byte, err error) {