@@ -14,6 +14,7 @@ import (
1414 "time"
1515
1616 "github.com/google/uuid"
17+ lru "github.com/hashicorp/golang-lru/v2"
1718 "golang.org/x/exp/slices"
1819 "golang.org/x/xerrors"
1920 "tailscale.com/tailcfg"
@@ -109,11 +110,17 @@ func ServeCoordinator(conn net.Conn, updateNodes func(node []*Node) error) (func
109110// coordinator is incompatible with multiple Coder replicas as all node data is
110111// in-memory.
111112func NewCoordinator () Coordinator {
113+ cache , err := lru.New [uuid.UUID , string ](512 )
114+ if err != nil {
115+ panic ("make lru cache: " + err .Error ())
116+ }
117+
112118 return & coordinator {
113119 closed : false ,
114120 nodes : map [uuid.UUID ]* Node {},
115121 agentSockets : map [uuid.UUID ]* trackedConn {},
116122 agentToConnectionSockets : map [uuid.UUID ]map [uuid.UUID ]* trackedConn {},
123+ agentNameCache : cache ,
117124 }
118125}
119126
@@ -135,6 +142,10 @@ type coordinator struct {
135142 // agentToConnectionSockets maps agent IDs to connection IDs of conns that
136143 // are subscribed to updates for that agent.
137144 agentToConnectionSockets map [uuid.UUID ]map [uuid.UUID ]* trackedConn
145+
146+ // agentNameCache holds a cache of agent names. If one of them disappears,
147+ // it's helpful to have a name cached for debugging.
148+ agentNameCache * lru.Cache [uuid.UUID , string ]
138149}
139150
140151type trackedConn struct {
@@ -288,6 +299,8 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) error
288299 return xerrors .New ("coordinator is closed" )
289300 }
290301
302+ c .agentNameCache .Add (id , name )
303+
291304 sockets , ok := c .agentToConnectionSockets [id ]
292305 if ok {
293306 // Publish all nodes that want to connect to the
@@ -532,7 +545,13 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) {
532545 fmt .Fprintln (w , "<ul>" )
533546
534547 for _ , agentConns := range missingAgents {
535- fmt .Fprintf (w , "<li style=\" margin-top:4px\" ><b>unknown</b> (<code>%s</code>): created ? ago, write ? ago, overwrites ? </li>\n " ,
548+ agentName , ok := c .agentNameCache .Get (agentConns .id )
549+ if ! ok {
550+ agentName = "unknown"
551+ }
552+
553+ fmt .Fprintf (w , "<li style=\" margin-top:4px\" ><b>%s</b> (<code>%s</code>): created ? ago, write ? ago, overwrites ? </li>\n " ,
554+ agentName ,
536555 agentConns .id .String (),
537556 )
538557
0 commit comments