From fb361dfe49e20b64de1e809bd248bddf0fc5f0f5 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Thu, 12 Feb 2026 11:11:59 +1000 Subject: [PATCH] fix: update instance status BEFORE calling it --- TODO.md | 2 ++ hive/daemon/daemon.go | 2 +- hive/daemon/daemon_handlers.go | 12 +++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 30ac69969..a1d153158 100644 --- a/TODO.md +++ b/TODO.md @@ -38,6 +38,8 @@ - migrate to list objects v2 - split up utils.go - make sure nats is running before we start daemon? eigw and account service will fallback to memory versions but that breaks all functionality +- the BlockDeviceMappings > DeviceName (/dev/xvda) is not the true volume, i think it's /dev/vda on mine. I think qmp has a query device stats which will provide block devices so we can match these up. not a blocker, but needs to be fixed eventually +- aws ec2 modify-instance-attribute ### Issues to investigate diff --git a/hive/daemon/daemon.go b/hive/daemon/daemon.go index f9efb809c..45a9bd056 100644 --- a/hive/daemon/daemon.go +++ b/hive/daemon/daemon.go @@ -621,7 +621,7 @@ func (d *Daemon) restoreInstances() { continue } - if instance.Attributes.StopInstance || instance.Status == vm.StateStopped { + if instance.Status == vm.StateStopped { slog.Info("Instance is stopped, subscribing to NATS for start commands", "instance", instance.ID) d.mu.Lock() sub, err := d.natsConn.Subscribe(fmt.Sprintf("ec2.cmd.%s", instance.ID), d.handleEC2Events) diff --git a/hive/daemon/daemon_handlers.go b/hive/daemon/daemon_handlers.go index 54915f141..7196d4720 100644 --- a/hive/daemon/daemon_handlers.go +++ b/hive/daemon/daemon_handlers.go @@ -474,6 +474,13 @@ func (d *Daemon) handleStartInstance(msg *nats.Msg, command qmp.Command, instanc } } + // Clear stop attribute before launch so WriteState inside LaunchInstance + // persists the correct attributes. Without this, a daemon restart after + // a stop→start cycle would see StopInstance=true and skip reconnecting QEMU. + d.Instances.Mu.Lock() + instance.Attributes = command.Attributes + d.Instances.Mu.Unlock() + // Launch the instance infrastructure (QEMU, QMP, NATS subscriptions) err := d.LaunchInstance(instance) @@ -487,11 +494,6 @@ func (d *Daemon) handleStartInstance(msg *nats.Msg, command qmp.Command, instanc return } - // Update instance attributes (LaunchInstance already transitions to StateRunning) - d.Instances.Mu.Lock() - instance.Attributes = command.Attributes - d.Instances.Mu.Unlock() - slog.Info("Instance started", "instanceId", instance.ID) if err := msg.Respond(fmt.Appendf(nil, `{"status":"running","instanceId":"%s"}`, instance.ID)); err != nil {