fix: update instance status BEFORE calling it

This commit is contained in:
Julian Sommer
2026-02-12 11:11:59 +10:00
parent 9d3747bf26
commit fb361dfe49
3 changed files with 10 additions and 6 deletions
+2
View File
@@ -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
+1 -1
View File
@@ -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)
+7 -5
View File
@@ -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 {