tstest/natlab/vnet: stop agent dials from outliving their Server

While a VM reboots, tests poll its agent roughly every 5s. Each
request that times out leaves behind a goroutine blocked in
Server.takeAgentConn, waiting for TTA to connect back. Several can
pile up before a request succeeds and the test ends, and the rest
wait forever.

Making takeAgentConn return at Server shutdown unblocks any goroutine
still waiting when the test ends.

In a full vmtest run, the two dials stranded by the reboot in
TestGokrazyUpdatesItselfToSameImage logged until the package exited
10 minutes later. With this change, "still waiting" log lines in the
same run drop from 267 to 72, and the longest wait goes from 10m10s
to 40s.

Updates #cleanup

Change-Id: Ib4c1d2ce8f2a7b73d3f0c1e6a9e5b2d8f4a1c7e3
Signed-off-by: Francois Marier <[email protected]>
This commit is contained in:
Francois Marier authored and François Marier committed 2026-10-06 11:48:17 -07:00
1 parent e28b7b57ef
commit 2d34ce3bbf
1 file changed
+8 -6
+8 -6
View File
@@ -2926,7 +2926,7 @@ func (s *Server) addIdleAgentConn(ac *agentConn) {
}
}
func (s *Server) takeAgentConn(ctx context.Context, n *node) (_ *agentConn, ok bool) {
func (s *Server) takeAgentConn(ctx context.Context, n *node) (*agentConn, error) {
const debug = false
// stuckThreshold is how long we wait before deciding the agent is slow
// enough to warrant a log line. Below this we stay quiet because, in
@@ -2941,7 +2941,7 @@ func (s *Server) takeAgentConn(ctx context.Context, n *node) (_ *agentConn, ok b
if debug {
log.Printf("takeAgentConn: got agent conn for %v", n.mac)
}
return ac, true
return ac, nil
}
if debug && miss > 0 {
log.Printf("takeAgentConnOne: missed %d times for %v", miss, n.mac)
@@ -2960,7 +2960,9 @@ func (s *Server) takeAgentConn(ctx context.Context, n *node) (_ *agentConn, ok b
}
select {
case <-ctx.Done():
return nil, false
return nil, ctx.Err()
case <-s.shutdownCtx.Done():
return nil, errors.New("takeAgentConn: server shut down while waiting for agent conn")
case <-ready:
case <-time.After(time.Second):
// Try again regularly anyway, in case we have multiple clients
@@ -3005,9 +3007,9 @@ func (s *Server) NodeAgentDialer(n *Node) netx.DialFunc {
return d
}
d := func(ctx context.Context, network, addr string) (net.Conn, error) {
ac, ok := s.takeAgentConn(ctx, n.n)
if !ok {
return nil, ctx.Err()
ac, err := s.takeAgentConn(ctx, n.n)
if err != nil {
return nil, err
}
return ac.tc, nil
}