Skip to content

Commit 79991a9

Browse files
committed
Fix coordinator locking
1 parent 08b9681 commit 79991a9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tailnet/coordinator.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID) error {
246246
}
247247

248248
sockets, ok := c.agentToConnectionSockets[id]
249-
c.mutex.Unlock()
250249
if ok {
251250
// Publish all nodes that want to connect to the
252251
// desired agent ID.
@@ -258,21 +257,21 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID) error {
258257
}
259258
nodes = append(nodes, node)
260259
}
260+
c.mutex.Unlock()
261261
data, err := json.Marshal(nodes)
262262
if err != nil {
263-
c.mutex.Unlock()
264263
return xerrors.Errorf("marshal json: %w", err)
265264
}
266265
_, err = conn.Write(data)
267266
if err != nil {
268267
return xerrors.Errorf("write nodes: %w", err)
269268
}
269+
c.mutex.Lock()
270270
}
271271

272272
// If an old agent socket is connected, we close it
273273
// to avoid any leaks. This shouldn't ever occur because
274274
// we expect one agent to be running.
275-
c.mutex.Lock()
276275
oldAgentSocket, ok := c.agentSockets[id]
277276
if ok {
278277
_ = oldAgentSocket.Close()

0 commit comments

Comments
 (0)