From 55513fbfda2a03278b287b2f2dca1097e7b5a073 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Wed, 16 Nov 2016 11:12:30 +0000 Subject: [PATCH] ciao-launcher: Send InstanceDeleted after instance deletion Launcher was incorrectly sending the InstanceDeleted event before the instance and its associated network assets had been deleted. This was causing a race condition in which controller was re-using some of the resources assigned to the instance before it was actually deleted for new instances. When this happened the new instances typically failed to start. This commit delays the sending of the InstanceDelete event until after the instance has been deleted. Fixes #808 Signed-off-by: Mark Ryan --- ciao-launcher/instance.go | 21 +++++++++++++++++++++ ciao-launcher/main.go | 1 - ciao-launcher/overseer.go | 22 ---------------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/ciao-launcher/instance.go b/ciao-launcher/instance.go index aac728ab0..35b4638ac 100644 --- a/ciao-launcher/instance.go +++ b/ciao-launcher/instance.go @@ -21,6 +21,8 @@ import ( "sync" "time" + yaml "gopkg.in/yaml.v2" + storage "github.com/01org/ciao/ciao-storage" "github.com/01org/ciao/payloads" "github.com/01org/ciao/ssntp" @@ -192,6 +194,24 @@ func (id *instanceData) stopCommand(cmd *insStopCmd) { id.monitorCh <- virtualizerStopCmd{} } +func (id *instanceData) sendInstanceDeletedEvent() { + var event payloads.EventInstanceDeleted + + event.InstanceDeleted.InstanceUUID = id.instance + + payload, err := yaml.Marshal(&event) + if err != nil { + glog.Errorf("Unable to Marshall STATS %v", err) + return + } + + _, err = id.ac.conn.SendEvent(ssntp.InstanceDeleted, payload) + if err != nil { + glog.Errorf("Failed to send event command %v", err) + return + } +} + func (id *instanceData) deleteCommand(cmd *insDeleteCmd) bool { if id.shuttingDown && !cmd.suicide { deleteErr := &deleteError{nil, payloads.DeleteNoInstance} @@ -211,6 +231,7 @@ func (id *instanceData) deleteCommand(cmd *insDeleteCmd) bool { id.unmapVolumes() if !cmd.suicide { + id.sendInstanceDeletedEvent() id.ovsCh <- &ovsStatusCmd{} } return true diff --git a/ciao-launcher/main.go b/ciao-launcher/main.go index d229f8ca7..7787fa8ad 100644 --- a/ciao-launcher/main.go +++ b/ciao-launcher/main.go @@ -362,7 +362,6 @@ func processCommand(conn serverConn, cmd *cmdWrapper, ovsCh chan<- interface{}) errCh := make(chan error) ovsCh <- &ovsRemoveCmd{ cmd.instance, - delCmd.suicide, errCh} <-errCh } diff --git a/ciao-launcher/overseer.go b/ciao-launcher/overseer.go index 2b26d21e3..e0d2427fb 100644 --- a/ciao-launcher/overseer.go +++ b/ciao-launcher/overseer.go @@ -58,7 +58,6 @@ type ovsGetCmd struct { type ovsRemoveCmd struct { instance string - suicide bool errCh chan<- error } @@ -494,24 +493,6 @@ func getStats(instancesDir string) *cnStats { return &s } -func (ovs *overseer) sendInstanceDeletedEvent(instance string) { - var event payloads.EventInstanceDeleted - - event.InstanceDeleted.InstanceUUID = instance - - payload, err := yaml.Marshal(&event) - if err != nil { - glog.Errorf("Unable to Marshall STATS %v", err) - return - } - - _, err = ovs.ac.conn.SendEvent(ssntp.InstanceDeleted, payload) - if err != nil { - glog.Errorf("Failed to send event command %v", err) - return - } -} - func (ovs *overseer) processGetCommand(cmd *ovsGetCmd) { glog.Infof("Overseer: looking for instance %s", cmd.instance) var insState ovsGetResult @@ -579,9 +560,6 @@ func (ovs *overseer) processRemoveCommand(cmd *ovsRemoveCmd) { } delete(ovs.instances, cmd.instance) - if !cmd.suicide { - ovs.sendInstanceDeletedEvent(cmd.instance) - } cmd.errCh <- nil }