diff --git a/internal/command/deploy/machines_deploymachinesapp.go b/internal/command/deploy/machines_deploymachinesapp.go index 0dc1da2331..dc994c538a 100644 --- a/internal/command/deploy/machines_deploymachinesapp.go +++ b/internal/command/deploy/machines_deploymachinesapp.go @@ -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() @@ -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 } @@ -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 { diff --git a/internal/command/deploy/strategy_bluegreen.go b/internal/command/deploy/strategy_bluegreen.go index cd75137870..5db6f245a4 100644 --- a/internal/command/deploy/strategy_bluegreen.go +++ b/internal/command/deploy/strategy_bluegreen.go @@ -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() diff --git a/internal/machine/leasable_machine.go b/internal/machine/leasable_machine.go index 244bb19613..dd5d495ec9 100644 --- a/internal/machine/leasable_machine.go +++ b/internal/machine/leasable_machine.go @@ -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,