From f287889cd7020be02b1b8ef2ebb83f18c0b69814 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 7 Mar 2023 10:46:54 -0600 Subject: [PATCH] chore: move client pubsub for HA coordinator after register (#6487) Similar fix that happened for the agent. See: https://github.com/coder/coder/actions/runs/4356099388/jobs/7613634277 --- enterprise/tailnet/coordinator.go | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/enterprise/tailnet/coordinator.go b/enterprise/tailnet/coordinator.go index e4ff982723..03450f6057 100644 --- a/enterprise/tailnet/coordinator.go +++ b/enterprise/tailnet/coordinator.go @@ -83,6 +83,21 @@ func (c *haCoordinator) Node(id uuid.UUID) *agpl.Node { // with the specified ID. func (c *haCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error { c.mutex.Lock() + connectionSockets, ok := c.agentToConnectionSockets[agent] + if !ok { + connectionSockets = map[uuid.UUID]*agpl.TrackedConn{} + c.agentToConnectionSockets[agent] = connectionSockets + } + + now := time.Now().Unix() + // Insert this connection into a map so the agent + // can publish node updates. + connectionSockets[id] = &agpl.TrackedConn{ + Conn: conn, + Start: now, + LastWrite: now, + } + // When a new connection is requested, we update it with the latest // node of the agent. This allows the connection to establish. node, ok := c.nodes[agent] @@ -103,23 +118,6 @@ func (c *haCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID } } - c.mutex.Lock() - connectionSockets, ok := c.agentToConnectionSockets[agent] - if !ok { - connectionSockets = map[uuid.UUID]*agpl.TrackedConn{} - c.agentToConnectionSockets[agent] = connectionSockets - } - - now := time.Now().Unix() - // Insert this connection into a map so the agent - // can publish node updates. - connectionSockets[id] = &agpl.TrackedConn{ - Conn: conn, - Start: now, - LastWrite: now, - } - c.mutex.Unlock() - defer func() { c.mutex.Lock() defer c.mutex.Unlock()