fix(tailnet): Improve tailnet setup and agentconn stability (#6292)

* fix(tailnet): Improve start and close to detect connection races

* fix: Prevent agentConn use before ready via AwaitReachable

* fix(tailnet): Ensure connstats are closed on conn close

* fix(codersdk): Use AwaitReachable in DialWorkspaceAgent

* fix(tailnet): Improve logging via slog.Helper()
This commit is contained in:
Mathias Fredriksson
2023-02-24 13:11:28 +02:00
committed by GitHub
parent 473ab208af
commit a414de9e81
6 changed files with 107 additions and 25 deletions

View File

@ -6,6 +6,7 @@ import (
"net/http"
"net/netip"
"strconv"
"sync"
"testing"
"github.com/stretchr/testify/assert"
@ -78,8 +79,14 @@ func TestDERP(t *testing.T) {
DERPMap: derpMap,
})
require.NoError(t, err)
w2Ready := make(chan struct{}, 1)
w2ReadyOnce := sync.Once{}
w1.SetNodeCallback(func(node *tailnet.Node) {
w2.UpdateNodes([]*tailnet.Node{node})
w2ReadyOnce.Do(func() {
close(w2Ready)
})
})
w2.SetNodeCallback(func(node *tailnet.Node) {
w1.UpdateNodes([]*tailnet.Node{node})
@ -98,6 +105,7 @@ func TestDERP(t *testing.T) {
}()
<-conn
<-w2Ready
nc, err := w2.DialContextTCP(context.Background(), netip.AddrPortFrom(w1IP, 35565))
require.NoError(t, err)
_ = nc.Close()