Skip to content

Commit

Permalink
fix: log the error from ReleaseLease
Browse files Browse the repository at this point in the history
  • Loading branch information
kzys committed Dec 9, 2024
1 parent a79536a commit b8c018f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions internal/command/deploy/machines_deploymachinesapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,14 @@ func (md *machineDeployment) updateEntriesGroup(parentCtx context.Context, group
return updatePool.Wait()
}

// releaseLease releases the lease and log the error if any.
func releaseLease(ctx context.Context, m machine.LeasableMachine) {
err := m.ReleaseLease(ctx)
if err != nil {
terminal.Warnf("failed to release lease for machine %s: %s", m.FormattedMachineId(), err)
}
}

func (md *machineDeployment) updateMachineByReplace(ctx context.Context, e *machineUpdateEntry) error {
ctx, span := tracing.GetTracer().Start(ctx, "update_by_replace", trace.WithAttributes(attribute.String("id", e.launchInput.ID)))
defer span.End()
Expand All @@ -981,7 +989,7 @@ func (md *machineDeployment) updateMachineByReplace(ctx context.Context, e *mach
}

lm = machine.NewLeasableMachine(md.flapsClient, md.io, newMachineRaw, false)
defer lm.ReleaseLease(ctx)
defer releaseLease(ctx, lm)
e.leasableMachine = lm
return nil
}
Expand Down Expand Up @@ -1059,7 +1067,7 @@ func (md *machineDeployment) spawnMachineInGroup(ctx context.Context, groupName

lm := machine.NewLeasableMachine(md.flapsClient, md.io, newMachineRaw, false)
statuslogger.Logf(ctx, "Machine %s was created", md.colorize.Bold(lm.FormattedMachineId()))
defer lm.ReleaseLease(ctx)
defer releaseLease(ctx, lm)

// Don't wait for SkipLaunch machines, they are created but not started
if launchInput.SkipLaunch {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/deploy/strategy_bluegreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (bg *blueGreen) CreateGreenMachines(ctx context.Context) error {
}

greenMachine := machine.NewLeasableMachine(bg.flaps, bg.io, newMachineRaw, true)
defer greenMachine.ReleaseLease(ctx)
defer releaseLease(ctx, greenMachine)

lock.Lock()
defer lock.Unlock()
Expand Down
4 changes: 3 additions & 1 deletion internal/machine/leasable_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ type leasableMachine struct {
leaseNonce string
}

// TODO: make sure the other functions handle showLogs correctly
// NewLeasableMachine creates a wrapper for the given machine.
// A lease must be held before calling this function.
func NewLeasableMachine(flapsClient flapsutil.FlapsClient, io *iostreams.IOStreams, machine *fly.Machine, showLogs bool) LeasableMachine {
// TODO: make sure the other functions handle showLogs correctly
return &leasableMachine{
flapsClient: flapsClient,
io: io,
Expand Down

0 comments on commit b8c018f

Please sign in to comment.