Skip to content

Commit

Permalink
feat: add spinner when tailscale takes longer than ususal
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Brecic <[email protected]>
  • Loading branch information
lbrecic committed Sep 26, 2024
1 parent 69df3fe commit c26e23b
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions pkg/cmd/workspace/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,34 @@ func waitForDial(workspace *apiclient.Workspace, activeProfile *config.Profile,
}
}

for {
dialConn, err := tsConn.Dial(context.Background(), "tcp", fmt.Sprintf("%s:%d", project.GetProjectHostname(workspace.Id, workspace.Projects[0].Name), ssh_config.SSH_PORT))
if err == nil {
return dialConn.Close()
connectChan := make(chan error)
spinner := time.After(3 * time.Second)
timeout := time.After(60 * time.Second)

go func() {
for {
dialConn, err := tsConn.Dial(context.Background(), "tcp", fmt.Sprintf("%s:%d", project.GetProjectHostname(workspace.Id, workspace.Projects[0].Name), ssh_config.SSH_PORT))
if err == nil {
connectChan <- dialConn.Close()
return
}
time.Sleep(time.Second)
}
}()

time.Sleep(time.Second)
select {
case err := <-connectChan:
return err
case <-spinner:
err := views_util.WithInlineSpinner("Connection to tailscale is taking longer than usual", func() error {
select {
case err := <-connectChan:
return err
case <-timeout:
return errors.New("secure connection to the Daytona Server could not be established. Please check your internet connection or Tailscale availability")
}
})
return err
}
}

Expand Down

0 comments on commit c26e23b

Please sign in to comment.