Skip to content

Commit

Permalink
actually fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Aug 13, 2021
1 parent 7462c12 commit 1b3b71c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
14 changes: 11 additions & 3 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ func (s *Server) handleEstablish(c net.Conn, args []string) error {
return writef(c, "ok")
}

func probeTunnel(tunnel *wg.Tunnel) error {
func probeTunnel(ctx context.Context, tunnel *wg.Tunnel) error {
var err error

terminal.Debugf("Probing WireGuard connectivity\n")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err = tunnel.Resolver().LookupTXT(ctx, "_apps.internal")
if err != nil {
Expand All @@ -273,7 +273,7 @@ func (s *Server) handleProbe(c net.Conn, args []string) error {
return fmt.Errorf("probe: can't build tunnel: %s", err)
}

if err := probeTunnel(tunnel); err != nil {
if err := probeTunnel(context.Background(), tunnel); err != nil {
captureWireguardConnErr(err, args[1])
return err
}
Expand Down Expand Up @@ -525,3 +525,11 @@ func Establish(ctx context.Context, apiClient *api.Client) (*Client, error) {

return StartDaemon(ctx, apiClient, os.Args[0])
}

type ErrProbeFailed struct {
Msg string
}

func (e *ErrProbeFailed) Error() string {
return fmt.Sprintf("probe failed: %s", e.Msg)
}
8 changes: 0 additions & 8 deletions pkg/agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ func (c *Client) WaitForTunnel(ctx context.Context, o *api.Organization) error {
}
}

type ErrProbeFailed struct {
Msg string
}

func (e *ErrProbeFailed) Error() string {
return fmt.Sprintf("probe failed: %s", e.Msg)
}

func (c *Client) Probe(ctx context.Context, o *api.Organization) error {
return c.withConnection(ctx, func(conn net.Conn) error {
writef(conn, "probe %s", o.Slug)
Expand Down
17 changes: 16 additions & 1 deletion pkg/agent/client_noagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package agent

import (
"context"
"errors"
"fmt"
"net"
"sync"
Expand Down Expand Up @@ -85,13 +86,27 @@ func (c *Client) Probe(ctx context.Context, o *api.Organization) error {
return fmt.Errorf("probe: can't build tunnel: %s", err)
}

if err := probeTunnel(tunnel); err != nil {
if err := probeTunnel(ctx, tunnel); err != nil {
return err
}

return nil
}

func (c *Client) WaitForTunnel(ctx context.Context, o *api.Organization) error {
for {
err := c.Probe(ctx, o)
switch {
case err == nil:
return nil
case err == context.Canceled || err == context.DeadlineExceeded:
return err
case errors.Is(err, &ErrProbeFailed{}):
continue
}
}
}

func (c *Client) Instances(ctx context.Context, o *api.Organization, app string) (*Instances, error) {
tunnel, err := c.tunnelFor(o.Slug)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/start_noagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package agent

import (
"context"
"fmt"

"github.com/superfly/flyctl/api"
Expand Down

0 comments on commit 1b3b71c

Please sign in to comment.