X Tutup
Skip to content

Commit b036061

Browse files
authored
Merge pull request cli#4521 from cli/jg/bind-locally
codespace: switches port binding to 127.0.0.1 where possible
2 parents c2abe17 + 0748e65 commit b036061

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

internal/codespaces/states.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func PollPostCreateStates(ctx context.Context, logger logger, apiClient apiClien
5252
}()
5353

5454
// Ensure local port is listening before client (getPostCreateOutput) connects.
55-
listen, err := net.Listen("tcp", ":0") // arbitrary port
55+
listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port
5656
if err != nil {
5757
return err
5858
}

pkg/cmd/codespace/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (a *App) Logs(ctx context.Context, codespaceName string, follow bool) (err
6262
}
6363

6464
// Ensure local port is listening before client (getPostCreateOutput) connects.
65-
listen, err := net.Listen("tcp", ":0") // arbitrary port
65+
listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port
6666
if err != nil {
6767
return err
6868
}

pkg/cmd/codespace/ssh.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
9494
usingCustomPort := localSSHServerPort != 0 // suppress log of command line in Shell
9595

9696
// Ensure local port is listening before client (Shell) connects.
97-
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", localSSHServerPort))
97+
// Unless the user specifies a server port, localSSHServerPort is 0
98+
// and thus the client will pick a random port.
99+
listen, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", localSSHServerPort))
98100
if err != nil {
99101
return err
100102
}

0 commit comments

Comments
 (0)
X Tutup