@@ -278,18 +278,21 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
278
278
_ , wsNetConn := websocketNetConn (ctx , conn , websocket .MessageBinary )
279
279
defer wsNetConn .Close () // Also closes conn.
280
280
281
+ fmt .Println ("getting conn from cache" )
281
282
agentConn , release , err := api .workspaceAgentCache .Acquire (r , workspaceAgent .ID )
282
283
if err != nil {
283
284
_ = conn .Close (websocket .StatusInternalError , httpapi .WebsocketCloseSprintf ("dial workspace agent: %s" , err ))
284
285
return
285
286
}
286
287
defer release ()
288
+ fmt .Println ("got conn from cache" )
287
289
ptNetConn , err := agentConn .ReconnectingPTY (ctx , reconnect , uint16 (height ), uint16 (width ), r .URL .Query ().Get ("command" ))
288
290
if err != nil {
289
291
_ = conn .Close (websocket .StatusInternalError , httpapi .WebsocketCloseSprintf ("dial: %s" , err ))
290
292
return
291
293
}
292
294
defer ptNetConn .Close ()
295
+ fmt .Println ("dialed reconnecting pty, doing bicopy" )
293
296
agent .Bicopy (ctx , wsNetConn , ptNetConn )
294
297
}
295
298
@@ -402,11 +405,11 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req
402
405
403
406
func (api * API ) dialWorkspaceAgentTailnet (r * http.Request , agentID uuid.UUID ) (* codersdk.AgentConn , error ) {
404
407
clientConn , serverConn := net .Pipe ()
405
- go func () {
406
- <- r .Context ().Done ()
407
- _ = clientConn .Close ()
408
- _ = serverConn .Close ()
409
- }()
408
+ // go func() {
409
+ // <-r.Context().Done()
410
+ // _ = clientConn.Close()
411
+ // _ = serverConn.Close()
412
+ // }()
410
413
411
414
derpMap := api .DERPMap .Clone ()
412
415
for _ , region := range derpMap .Regions {
@@ -453,7 +456,16 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
453
456
}
454
457
455
458
sendNodes , _ := tailnet .ServeCoordinator (clientConn , func (node []* tailnet.Node ) error {
456
- return conn .UpdateNodes (node )
459
+ err := conn .RemoveAllPeers ()
460
+ if err != nil {
461
+ return xerrors .Errorf ("remove all peers: %w" , err )
462
+ }
463
+
464
+ err = conn .UpdateNodes (node )
465
+ if err != nil {
466
+ return xerrors .Errorf ("update nodes: %w" , err )
467
+ }
468
+ return nil
457
469
})
458
470
conn .SetNodeCallback (sendNodes )
459
471
go func () {
@@ -465,6 +477,10 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
465
477
}()
466
478
return & codersdk.AgentConn {
467
479
Conn : conn ,
480
+ CloseFunc : func () {
481
+ _ = clientConn .Close ()
482
+ _ = serverConn .Close ()
483
+ },
468
484
}, nil
469
485
}
470
486
0 commit comments