Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 00667ef

Browse files
authored
feat: Durability test RTC connections (#329)
* Move dial and listen to wsnet * Return proper errors from dial ice * Test sending data * Fix test race * Add disconnect err test * Transfer to use wsnet * Fix xwebrtc reference * Fix comment * Fix go.mod * Fix linting * Fix linting issues * Ignore race conditions for testing the broker * Fix import order * Fix race conditions * Fix trailing whitespace * Ensure proper networking errors get surfaced * Remove agent retry * Fix tunnel command with multiple connections * Reduce API surface
1 parent 9806f29 commit 00667ef

22 files changed

+1289
-741
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ ci/integration/bin
66
ci/integration/env.sh
77
coder-sdk/env.sh
88
.vscode
9+
vendor

agent/doc.go

Lines changed: 0 additions & 2 deletions
This file was deleted.

agent/server.go

Lines changed: 0 additions & 106 deletions
This file was deleted.

agent/stream.go

Lines changed: 0 additions & 194 deletions
This file was deleted.

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ require (
1313
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
1414
github.com/klauspost/compress v1.10.8 // indirect
1515
github.com/manifoldco/promptui v0.8.0
16+
github.com/pion/datachannel v1.4.21
17+
github.com/pion/dtls/v2 v2.0.9
18+
github.com/pion/ice/v2 v2.1.5
19+
github.com/pion/turn/v2 v2.0.5
1620
github.com/pion/webrtc/v3 v3.0.24
1721
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
1822
github.com/rjeczalik/notify v0.9.2
1923
github.com/spf13/cobra v1.1.3
20-
go.coder.com/retry v1.2.0
21-
golang.org/x/net v0.0.0-20210420210106-798c2154c571
2224
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
2325
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe
2426
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
361361
go.coder.com/cli v0.4.0/go.mod h1:hRTOURCR3LJF1FRW9arecgrzX+AHG7mfYMwThPIgq+w=
362362
go.coder.com/flog v0.0.0-20190906214207-47dd47ea0512 h1:DjCS6dRQh+1PlfiBmnabxfdrzenb0tAwJqFxDEH/s9g=
363363
go.coder.com/flog v0.0.0-20190906214207-47dd47ea0512/go.mod h1:83JsYgXYv0EOaXjIMnaZ1Fl6ddNB3fJnDZ/8845mUJ8=
364-
go.coder.com/retry v1.2.0 h1:ODdUPu9cb9pcbeAM5j2YqJHUgfFbN60vmhtlWIKZGLo=
365-
go.coder.com/retry v1.2.0/go.mod h1:ihkJszQk8F+yaFL2pcIku9MzbYo+U8vka4IsvQSXVfE=
366364
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
367365
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
368366
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=

internal/cmd/agent.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package cmd
22

33
import (
44
"context"
5+
"log"
56
"net/url"
67
"os"
8+
"os/signal"
9+
"syscall"
710

8-
"cdr.dev/slog"
9-
"cdr.dev/slog/sloggers/sloghuman"
1011
"github.com/spf13/cobra"
1112
"golang.org/x/xerrors"
1213

13-
"cdr.dev/coder-cli/agent"
14+
"cdr.dev/coder-cli/wsnet"
1415
)
1516

1617
func agentCmd() *cobra.Command {
@@ -46,8 +47,6 @@ coder agent start --coder-url https://my-coder.com --token xxxx-xxxx
4647
`,
4748
RunE: func(cmd *cobra.Command, args []string) error {
4849
ctx := cmd.Context()
49-
log := slog.Make(sloghuman.Sink(cmd.OutOrStdout()))
50-
5150
if coderURL == "" {
5251
var ok bool
5352
coderURL, ok = os.LookupEnv("CODER_URL")
@@ -74,18 +73,18 @@ coder agent start --coder-url https://my-coder.com --token xxxx-xxxx
7473
}
7574
}
7675

77-
server, err := agent.NewServer(agent.ServerArgs{
78-
Log: log,
79-
CoderURL: u,
80-
Token: token,
81-
})
76+
listener, err := wsnet.Listen(context.Background(), wsnet.ListenEndpoint(u, token))
8277
if err != nil {
83-
return xerrors.Errorf("creating agent server: %w", err)
78+
return xerrors.Errorf("listen: %w", err)
8479
}
8580

86-
err = server.Run(ctx)
87-
if err != nil && !xerrors.Is(err, context.Canceled) && !xerrors.Is(err, context.DeadlineExceeded) {
88-
return xerrors.Errorf("running agent server: %w", err)
81+
// Block until user sends SIGINT or SIGTERM
82+
sigs := make(chan os.Signal, 1)
83+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
84+
<-sigs
85+
86+
if err = listener.Close(); err != nil {
87+
log.Panic(err)
8988
}
9089

9190
return nil

0 commit comments

Comments
 (0)