Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f287889

Browse files
authored
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
1 parent 4c204fc commit f287889

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

enterprise/tailnet/coordinator.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ func (c *haCoordinator) Node(id uuid.UUID) *agpl.Node {
8383
// with the specified ID.
8484
func (c *haCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error {
8585
c.mutex.Lock()
86+
connectionSockets, ok := c.agentToConnectionSockets[agent]
87+
if !ok {
88+
connectionSockets = map[uuid.UUID]*agpl.TrackedConn{}
89+
c.agentToConnectionSockets[agent] = connectionSockets
90+
}
91+
92+
now := time.Now().Unix()
93+
// Insert this connection into a map so the agent
94+
// can publish node updates.
95+
connectionSockets[id] = &agpl.TrackedConn{
96+
Conn: conn,
97+
Start: now,
98+
LastWrite: now,
99+
}
100+
86101
// When a new connection is requested, we update it with the latest
87102
// node of the agent. This allows the connection to establish.
88103
node, ok := c.nodes[agent]
@@ -103,23 +118,6 @@ func (c *haCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID
103118
}
104119
}
105120

106-
c.mutex.Lock()
107-
connectionSockets, ok := c.agentToConnectionSockets[agent]
108-
if !ok {
109-
connectionSockets = map[uuid.UUID]*agpl.TrackedConn{}
110-
c.agentToConnectionSockets[agent] = connectionSockets
111-
}
112-
113-
now := time.Now().Unix()
114-
// Insert this connection into a map so the agent
115-
// can publish node updates.
116-
connectionSockets[id] = &agpl.TrackedConn{
117-
Conn: conn,
118-
Start: now,
119-
LastWrite: now,
120-
}
121-
c.mutex.Unlock()
122-
123121
defer func() {
124122
c.mutex.Lock()
125123
defer c.mutex.Unlock()

0 commit comments

Comments
 (0)