mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
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:
committed by
GitHub
parent
473ab208af
commit
a414de9e81
@ -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()
|
||||
|
@ -469,6 +469,8 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
setup := func(t *testing.T, apps []*proto.App) (*codersdk.Client, uint16, uuid.UUID) {
|
||||
t.Helper()
|
||||
|
||||
client := coderdtest.New(t, &coderdtest.Options{
|
||||
IncludeProvisionerDaemon: true,
|
||||
})
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
"github.com/coder/coder/codersdk/agentsdk"
|
||||
"github.com/coder/coder/tailnet"
|
||||
"github.com/coder/coder/tailnet/tailnettest"
|
||||
"github.com/coder/coder/testutil"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -131,6 +132,14 @@ func TestCache(t *testing.T) {
|
||||
return
|
||||
}
|
||||
defer release()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
|
||||
defer cancel()
|
||||
if !conn.AwaitReachable(ctx) {
|
||||
t.Error("agent not reachable")
|
||||
return
|
||||
}
|
||||
|
||||
transport := conn.HTTPTransport()
|
||||
defer transport.CloseIdleConnections()
|
||||
proxy.Transport = transport
|
||||
@ -146,6 +155,8 @@ func TestCache(t *testing.T) {
|
||||
}
|
||||
|
||||
func setupAgent(t *testing.T, metadata agentsdk.Metadata, ptyTimeout time.Duration) *codersdk.WorkspaceAgentConn {
|
||||
t.Helper()
|
||||
|
||||
metadata.DERPMap = tailnettest.RunDERPAndSTUN(t)
|
||||
|
||||
coordinator := tailnet.NewCoordinator()
|
||||
|
Reference in New Issue
Block a user