Skip to content

Commit

Permalink
kill background agents if versions don't match
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Aug 23, 2021
1 parent a4b6f50 commit bace12a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pkg/agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"net"
"os"
"strings"
"time"

"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/internal/buildinfo"
"github.com/superfly/flyctl/internal/wireguard"
"github.com/superfly/flyctl/terminal"
)

/// Establish starts the daemon if necessary and returns a client
Expand All @@ -21,9 +24,25 @@ func Establish(ctx context.Context, apiClient *api.Client) (*Client, error) {

c, err := DefaultClient(apiClient)
if err == nil {
_, err := c.Ping(ctx)
resp, err := c.Ping(ctx)
if err == nil {
return c, nil
if buildinfo.Version().EQ(resp.Version) {
return c, nil
}

msg := fmt.Sprintf("flyctl version %s does not match agent version %s", buildinfo.Version(), resp.Version)

if !resp.Background {
terminal.Warn(msg)
return c, nil
}

if err := c.Kill(ctx); err != nil {
terminal.Warn(msg)
return nil, errors.Wrap(err, "kill failed")
}
// this is gross, but we need to wait for the agent to exit
time.Sleep(1 * time.Second)
}
}

Expand Down

0 comments on commit bace12a

Please sign in to comment.