mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user