Skip to content

Commit

Permalink
fix: port forward deadlock (#737)
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak authored Jul 8, 2024
1 parent 7e56080 commit ddde265
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/cmd/tailscale/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"io"
"net"

"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/pkg/ports"
"github.com/daytonaio/daytona/pkg/tailscale"
"github.com/daytonaio/daytona/pkg/workspace"
"tailscale.com/tsnet"
)

func ForwardPort(workspaceId, projectName string, targetPort uint16) (*uint16, chan error) {
func ForwardPort(workspaceId, projectName string, targetPort uint16, profile config.Profile) (*uint16, chan error) {
hostPort := targetPort
errChan := make(chan error)
var err error
Expand All @@ -27,7 +27,7 @@ func ForwardPort(workspaceId, projectName string, targetPort uint16) (*uint16, c
}
}

tsConn, err := tailscale.GetConnection(nil)
tsConn, err := GetConnection(&profile)
if err != nil {
errChan <- err
return nil, errChan
Expand Down
12 changes: 11 additions & 1 deletion pkg/cmd/ports/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"time"

"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/internal/cmd/tailscale"
"github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/pkg/frpc"
Expand All @@ -29,6 +30,15 @@ var PortForwardCmd = &cobra.Command{
Short: "Forward a port from a project to your local machine",
Args: cobra.RangeArgs(2, 3),
Run: func(cmd *cobra.Command, args []string) {
c, err := config.GetConfig()
if err != nil {
log.Fatal(err)
}
activeProfile, err := c.GetActiveProfile()
if err != nil {
log.Fatal(err)
}

port, err := strconv.Atoi(args[0])
if err != nil {
log.Fatal(err)
Expand All @@ -48,7 +58,7 @@ var PortForwardCmd = &cobra.Command{
}
}

hostPort, errChan := tailscale.ForwardPort(workspaceId, projectName, uint16(port))
hostPort, errChan := tailscale.ForwardPort(workspaceId, projectName, uint16(port), activeProfile)

if hostPort == nil {
if err = <-errChan; err != nil {
Expand Down
12 changes: 11 additions & 1 deletion pkg/cmd/workspacemode/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strconv"

"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/internal/cmd/tailscale"
defaultPortForwardCmd "github.com/daytonaio/daytona/pkg/cmd/ports"
"github.com/daytonaio/daytona/pkg/views"
Expand All @@ -21,12 +22,21 @@ var portForwardCmd = &cobra.Command{
Short: "Forward a port from the project to your local machine",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
c, err := config.GetConfig()
if err != nil {
log.Fatal(err)
}
activeProfile, err := c.GetActiveProfile()
if err != nil {
log.Fatal(err)
}

port, err := strconv.Atoi(args[0])
if err != nil {
log.Fatal(err)
}

hostPort, errChan := tailscale.ForwardPort(workspaceId, projectName, uint16(port))
hostPort, errChan := tailscale.ForwardPort(workspaceId, projectName, uint16(port), activeProfile)

if hostPort == nil {
if err = <-errChan; err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ide/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func OpenBrowserIDE(activeProfile config.Profile, workspaceId string, projectNam
}()

// Forward IDE port
browserPort, errChan := tailscale.ForwardPort(workspaceId, projectName, 63000)
browserPort, errChan := tailscale.ForwardPort(workspaceId, projectName, 63000, activeProfile)
if browserPort == nil {
if err := <-errChan; err != nil {
return err
Expand Down

0 comments on commit ddde265

Please sign in to comment.