diff --git a/server/instances.go b/server/instances.go index 2b9b23a2c..1a63efbb2 100644 --- a/server/instances.go +++ b/server/instances.go @@ -176,29 +176,22 @@ func (p *Plugin) UninstallInstance(instanceID types.ID, instanceType InstanceTyp if err != nil { if strings.Contains(err.Error(), "not found") { instances.Delete(instanceID) - updated = instances if err = p.instanceStore.StoreInstances(instances); err != nil { return err } + if err = p.disconnectUsers(instance); err != nil { + return err + } + return nil } - return nil + + return err } if instanceType != instance.Common().Type { return errors.Errorf("%s did not match instance %s type %s", instanceType, instanceID, instance.Common().Type) } - err = p.userStore.MapUsers(func(user *User) error { - if !user.ConnectedInstances.Contains(instance.GetID()) { - return nil - } - - _, err = p.disconnectUser(instance, user) - if err != nil { - p.infof("UninstallInstance: failed to disconnect user: %v", err) - } - return nil - }) - if err != nil { + if err = p.disconnectUsers(instance); err != nil { return err } @@ -222,6 +215,24 @@ func (p *Plugin) UninstallInstance(instanceID types.ID, instanceType InstanceTyp return instance, nil } +func (p *Plugin) disconnectUsers(instance Instance) error { + err := p.userStore.MapUsers(func(user *User) error { + if !user.ConnectedInstances.Contains(instance.GetID()) { + return nil + } + + _, err := p.disconnectUser(instance, user) + if err != nil { + p.infof("UninstallInstance: failed to disconnect user: %v", err) + } + return nil + }) + if err != nil { + return err + } + return nil +} + func (p *Plugin) wsInstancesChanged(instances *Instances) { msg := map[string]interface{}{ "instances": instances.AsConfigMap(),