diff --git a/lib/web/app/transport.go b/lib/web/app/transport.go index a25e8c0c9b8a8..408cf0a24c8da 100644 --- a/lib/web/app/transport.go +++ b/lib/web/app/transport.go @@ -386,12 +386,18 @@ func (t *transport) DialContext(ctx context.Context, _, _ string) (conn net.Conn break } - // eliminate any servers from the head of the list that were unreachable t.mu.Lock() - if i < len(servers) { - t.c.servers = t.c.servers[i:] - } else { - t.c.servers = nil + // Only attempt to tidy up the list of servers if they weren't altered + // while the dialing happened. Since the lock is only held initially when + // making the servers copy and released during the dials, another dial attempt + // may have already happened and modified the list of servers. + if len(servers) == len(t.c.servers) { + // eliminate any servers from the head of the list that were unreachable + if i < len(t.c.servers) { + t.c.servers = t.c.servers[i:] + } else { + t.c.servers = nil + } } t.mu.Unlock()