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

Commit42371eb

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 commit42371eb

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
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)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp