Make StartInstance and StopInstance idempotent

This commit is contained in:
2025-10-21 18:49:49 +02:00
parent a2d4622486
commit 7c64ab9cc6

View File

@@ -383,8 +383,9 @@ func (im *instanceManager) StartInstance(name string) (*instance.Instance, error
lock.Lock()
defer lock.Unlock()
// Idempotent: if already running, just return success
if inst.IsRunning() {
return inst, fmt.Errorf("instance with name %s is already running", name)
return inst, nil
}
// Check max running instances limit for local instances only
@@ -446,8 +447,9 @@ func (im *instanceManager) StopInstance(name string) (*instance.Instance, error)
lock.Lock()
defer lock.Unlock()
// Idempotent: if already stopped, just return success
if !inst.IsRunning() {
return inst, fmt.Errorf("instance with name %s is already stopped", name)
return inst, nil
}
if err := inst.Stop(); err != nil {