Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3800681

Browse files
committed
fix: Wait for connections before port-forwarding
UDP packets were being dropped if a connection was startedbefore the Tailscale connection has been established.
1 parentb20ecfd commit3800681

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

‎cli/portforward.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import (
1010
"strings"
1111
"sync"
1212
"syscall"
13+
"time"
1314

1415
"github.com/pion/udp"
1516
"github.com/spf13/cobra"
1617
"golang.org/x/xerrors"
1718

1819
"cdr.dev/slog"
20+
"cdr.dev/slog/sloggers/sloghuman"
1921
"github.com/coder/coder/agent"
22+
"github.com/coder/coder/cli/cliflag"
2023
"github.com/coder/coder/cli/cliui"
2124
"github.com/coder/coder/codersdk"
2225
)
@@ -95,7 +98,11 @@ func portForward() *cobra.Command {
9598
if!wireguard {
9699
conn,err=client.DialWorkspaceAgent(ctx,workspaceAgent.ID,nil)
97100
}else {
98-
conn,err=client.DialWorkspaceAgentTailnet(ctx, slog.Logger{},workspaceAgent.ID)
101+
logger:= slog.Logger{}
102+
ifcliflag.IsSetBool(cmd,varVerbose) {
103+
logger=slog.Make(sloghuman.Sink(cmd.ErrOrStderr())).Named("tailnet").Leveled(slog.LevelDebug)
104+
}
105+
conn,err=client.DialWorkspaceAgentTailnet(ctx,logger,workspaceAgent.ID)
99106
}
100107
iferr!=nil {
101108
returnerr
@@ -147,6 +154,22 @@ func portForward() *cobra.Command {
147154
closeAllListeners()
148155
}()
149156

157+
ticker:=time.NewTicker(250*time.Millisecond)
158+
deferticker.Stop()
159+
for {
160+
select {
161+
case<-ctx.Done():
162+
returnctx.Err()
163+
case<-ticker.C:
164+
}
165+
166+
_,err=conn.Ping()
167+
iferr!=nil {
168+
continue
169+
}
170+
break
171+
}
172+
ticker.Stop()
150173
_,_=fmt.Fprintln(cmd.OutOrStderr(),"Ready!")
151174
wg.Wait()
152175
returncloseErr

‎cli/portforward_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestPortForward(t *testing.T) {
133133

134134
// Launch port-forward in a goroutine so we can start dialing
135135
// the "local" listener.
136-
cmd,root:=clitest.New(t,"port-forward",workspace.Name,flag)
136+
cmd,root:=clitest.New(t,"-v","port-forward",workspace.Name,flag)
137137
clitest.SetupConfig(t,client,root)
138138
buf:=newThreadSafeBuffer()
139139
cmd.SetOut(buf)
@@ -179,7 +179,7 @@ func TestPortForward(t *testing.T) {
179179

180180
// Launch port-forward in a goroutine so we can start dialing
181181
// the "local" listeners.
182-
cmd,root:=clitest.New(t,"port-forward",workspace.Name,flag1,flag2)
182+
cmd,root:=clitest.New(t,"-v","port-forward",workspace.Name,flag1,flag2)
183183
clitest.SetupConfig(t,client,root)
184184
buf:=newThreadSafeBuffer()
185185
cmd.SetOut(buf)
@@ -234,7 +234,7 @@ func TestPortForward(t *testing.T) {
234234

235235
// Launch port-forward in a goroutine so we can start dialing
236236
// the "local" listeners.
237-
cmd,root:=clitest.New(t,append([]string{"port-forward",workspace.Name},flags...)...)
237+
cmd,root:=clitest.New(t,append([]string{"-v","port-forward",workspace.Name},flags...)...)
238238
clitest.SetupConfig(t,client,root)
239239
buf:=newThreadSafeBuffer()
240240
cmd.SetOut(buf)

‎cli/schedule_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,20 @@ func TestScheduleShow(t *testing.T) {
6161
t.Parallel()
6262

6363
var (
64-
ctx=context.Background()
6564
client=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
6665
user=coderdtest.CreateFirstUser(t,client)
6766
version=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,nil)
6867
_=coderdtest.AwaitTemplateVersionJob(t,client,version.ID)
6968
project=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID)
7069
workspace=coderdtest.CreateWorkspace(t,client,user.OrganizationID,project.ID,func(cwr*codersdk.CreateWorkspaceRequest) {
7170
cwr.AutostartSchedule=nil
71+
cwr.TTLMillis=nil
7272
})
73+
_=coderdtest.AwaitWorkspaceBuildJob(t,client,workspace.LatestBuild.ID)
7374
cmdArgs= []string{"schedule","show",workspace.Name}
7475
stdoutBuf=&bytes.Buffer{}
7576
)
7677

77-
// unset workspace TTL
78-
require.NoError(t,client.UpdateWorkspaceTTL(ctx,workspace.ID, codersdk.UpdateWorkspaceTTLRequest{TTLMillis:nil}))
79-
8078
cmd,root:=clitest.New(t,cmdArgs...)
8179
clitest.SetupConfig(t,client,root)
8280
cmd.SetOut(stdoutBuf)

‎go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ replace github.com/tcnksm/go-httpstat => github.com/kylecarbs/go-httpstat v0.0.0
4747

4848
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
4949
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
50-
replacetailscale.com =>github.com/coder/tailscalev1.1.1-0.20220912224234-e80caec6c05f
50+
replacetailscale.com =>github.com/coder/tailscalev1.1.1-0.20220914175845-85b85d9a52ee
5151

5252
// Switch to our fork that imports fixes from http://github.com/tailscale/ssh.
5353
// See: https://github.com/coder/coder/issues/3371

‎go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ github.com/coder/retry v1.3.0 h1:5lAAwt/2Cm6lVmnfBY7sOMXcBOwcwJhmV5QGSELIVWY=
355355
github.com/coder/retryv1.3.0/go.mod h1:tXuRgZgWjUnU5LZPT4lJh4ew2elUhexhlnXzrJWdyFY=
356356
github.com/coder/sshv0.0.0-20220811105153-fcea99919338 h1:tN5GKFT68YLVzJoA8AHuiMNJ0qlhoD3pGN3JY9gxSko=
357357
github.com/coder/sshv0.0.0-20220811105153-fcea99919338/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
358-
github.com/coder/tailscalev1.1.1-0.20220912224234-e80caec6c05f h1:NN9O1Pgno2QQy+JBnZk1VQ3vyAmWaB+yEotUDEuFKm8=
359-
github.com/coder/tailscalev1.1.1-0.20220912224234-e80caec6c05f/go.mod h1:5amxy08qijEa8bcTW2SeIy4MIqcmd7LMsuOxqOlj2Ak=
358+
github.com/coder/tailscalev1.1.1-0.20220914175845-85b85d9a52ee h1:77WUcIAL5FRQtd97/gOV66MJHLPhsPw+3vMxoEvcadI=
359+
github.com/coder/tailscalev1.1.1-0.20220914175845-85b85d9a52ee/go.mod h1:5amxy08qijEa8bcTW2SeIy4MIqcmd7LMsuOxqOlj2Ak=
360360
github.com/coder/wireguard-gov0.0.0-20220913030931-b1b3bb45caf9 h1:AeU4w8hSB+XEj3e8HjvEUTy/MWQd6tddnr9dELrRjKk=
361361
github.com/coder/wireguard-gov0.0.0-20220913030931-b1b3bb45caf9/go.mod h1:enML0deDxY1ux+B6ANGiwtg0yAJi1rctkTpcHNAVPyg=
362362
github.com/containerd/aufsv0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp