@@ -14,6 +14,7 @@ import (
14
14
"time"
15
15
16
16
"github.com/google/uuid"
17
+ lru "github.com/hashicorp/golang-lru/v2"
17
18
"golang.org/x/exp/slices"
18
19
"golang.org/x/xerrors"
19
20
"tailscale.com/tailcfg"
@@ -109,11 +110,17 @@ func ServeCoordinator(conn net.Conn, updateNodes func(node []*Node) error) (func
109
110
// coordinator is incompatible with multiple Coder replicas as all node data is
110
111
// in-memory.
111
112
func NewCoordinator () Coordinator {
113
+ cache , err := lru.New [uuid.UUID , string ](512 )
114
+ if err != nil {
115
+ panic ("make lru cache: " + err .Error ())
116
+ }
117
+
112
118
return & coordinator {
113
119
closed : false ,
114
120
nodes : map [uuid.UUID ]* Node {},
115
121
agentSockets : map [uuid.UUID ]* trackedConn {},
116
122
agentToConnectionSockets : map [uuid.UUID ]map [uuid.UUID ]* trackedConn {},
123
+ agentNameCache : cache ,
117
124
}
118
125
}
119
126
@@ -135,6 +142,10 @@ type coordinator struct {
135
142
// agentToConnectionSockets maps agent IDs to connection IDs of conns that
136
143
// are subscribed to updates for that agent.
137
144
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 ]
138
149
}
139
150
140
151
type trackedConn struct {
@@ -288,6 +299,8 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID, name string) error
288
299
return xerrors .New ("coordinator is closed" )
289
300
}
290
301
302
+ c .agentNameCache .Add (id , name )
303
+
291
304
sockets , ok := c .agentToConnectionSockets [id ]
292
305
if ok {
293
306
// Publish all nodes that want to connect to the
@@ -532,7 +545,13 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, _ *http.Request) {
532
545
fmt .Fprintln (w , "<ul>" )
533
546
534
547
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 ,
536
555
agentConns .id .String (),
537
556
)
538
557
0 commit comments