Skip to content

Commit d3983e4

Browse files
authored
feat: add logging to client tailnet yamux (#11908)
Adds logging to yamux when used for tailnet client connections, e.g. CLI and wsproxy. This could be useful for debugging connection issues with tailnet v2 API.
1 parent 0eff646 commit d3983e4

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

codersdk/workspaceagents.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ func (tac *tailnetAPIConnector) dial() (proto.DRPCTailnetClient, error) {
436436
}
437437
return nil, err
438438
}
439-
client, err := tailnet.NewDRPCClient(websocket.NetConn(tac.ctx, ws, websocket.MessageBinary))
439+
client, err := tailnet.NewDRPCClient(
440+
websocket.NetConn(tac.ctx, ws, websocket.MessageBinary),
441+
tac.logger,
442+
)
440443
if err != nil {
441444
tac.logger.Debug(tac.ctx, "failed to create DRPCClient", slog.Error(err))
442445
_ = ws.Close(websocket.StatusInternalError, "")

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
458458
go httpapi.HeartbeatClose(ctx, logger, cancel, conn)
459459

460460
nc := websocket.NetConn(ctx, conn, websocket.MessageBinary)
461-
client, err := agpl.NewDRPCClient(nc)
461+
client, err := agpl.NewDRPCClient(nc, logger)
462462
if err != nil {
463463
logger.Debug(ctx, "failed to create DRPCClient", slog.Error(err))
464464
_ = conn.Close(websocket.StatusInternalError, "")
@@ -488,7 +488,9 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
488488

489489
go func() {
490490
<-ctx.Done()
491-
ma.Close()
491+
_ = ma.Close()
492+
_ = client.DRPCConn().Close()
493+
<-client.DRPCConn().Closed()
492494
_ = conn.Close(websocket.StatusGoingAway, "closed")
493495
}()
494496

tailnet/client.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package tailnet
22

33
import (
4-
"io"
4+
"context"
55
"net"
66

77
"github.com/hashicorp/yamux"
88
"golang.org/x/xerrors"
99

10+
"cdr.dev/slog"
1011
"github.com/coder/coder/v2/codersdk/drpc"
1112
"github.com/coder/coder/v2/tailnet/proto"
1213
)
1314

14-
func NewDRPCClient(conn net.Conn) (proto.DRPCTailnetClient, error) {
15+
func NewDRPCClient(conn net.Conn, logger slog.Logger) (proto.DRPCTailnetClient, error) {
1516
config := yamux.DefaultConfig()
16-
config.LogOutput = io.Discard
17+
config.LogOutput = nil
18+
config.Logger = slog.Stdlib(context.Background(), logger, slog.LevelInfo)
1719
session, err := yamux.Client(conn, config)
1820
if err != nil {
1921
return nil, xerrors.Errorf("multiplex client: %w", err)

tailnet/coordinator_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func TestRemoteCoordination(t *testing.T) {
464464
serveErr <- err
465465
}()
466466

467-
client, err := tailnet.NewDRPCClient(cC)
467+
client, err := tailnet.NewDRPCClient(cC, logger)
468468
require.NoError(t, err)
469469
protocol, err := client.Coordinate(ctx)
470470
require.NoError(t, err)

tailnet/service_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestClientService_ServeClient_V2(t *testing.T) {
5151
errCh <- err
5252
}()
5353

54-
client, err := tailnet.NewDRPCClient(c)
54+
client, err := tailnet.NewDRPCClient(c, logger)
5555
require.NoError(t, err)
5656

5757
// Coordinate

0 commit comments

Comments
 (0)