Merge pull request #4521 from cli/jg/bind-locally

codespace: switches port binding to 127.0.0.1 where possible
This commit is contained in:
Mislav Marohnić 2021-10-14 20:29:21 +02:00 committed by GitHub
commit b0360612d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View file

@ -52,7 +52,7 @@ func PollPostCreateStates(ctx context.Context, logger logger, apiClient apiClien
}()
// Ensure local port is listening before client (getPostCreateOutput) connects.
listen, err := net.Listen("tcp", ":0") // arbitrary port
listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port
if err != nil {
return err
}

View file

@ -62,7 +62,7 @@ func (a *App) Logs(ctx context.Context, codespaceName string, follow bool) (err
}
// Ensure local port is listening before client (getPostCreateOutput) connects.
listen, err := net.Listen("tcp", ":0") // arbitrary port
listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port
if err != nil {
return err
}

View file

@ -94,7 +94,9 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
usingCustomPort := localSSHServerPort != 0 // suppress log of command line in Shell
// Ensure local port is listening before client (Shell) connects.
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", localSSHServerPort))
// Unless the user specifies a server port, localSSHServerPort is 0
// and thus the client will pick a random port.
listen, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", localSSHServerPort))
if err != nil {
return err
}