From 920892ec4af4ff15c21e9f9bcfcadecfa7de4875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Wed, 2 Dec 2015 20:23:51 +0000 Subject: [PATCH 1/4] fix halt logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - timeout to cover the case where the VM hanged on shutdown - only clean cruft if VM really down Signed-off-by: António Meireles --- halt.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/halt.go b/halt.go index 1e70358..7845344 100644 --- a/halt.go +++ b/halt.go @@ -87,22 +87,23 @@ func (vm VMInfo) halt() (err error) { } } } - // wait until it's _really_ dead - defer func() { - leftover := filepath.Join(SessionContext.runDir, vm.UUID) - - for range time.Tick(500 * time.Millisecond) { + // wait until it's _really_ dead, but not forever + for { + select { + case <-time.After(3 * time.Second): + return fmt.Errorf("VM didn't shutdown normally after 3s (!)... ") + case <-time.Tick(100 * time.Millisecond): if _, ee := os.FindProcess(vm.Pid); ee == nil { - break + if e := + os.RemoveAll(filepath.Join(SessionContext.runDir, + vm.UUID)); e != nil { + log.Println(e.Error()) + } + log.Printf("successfully halted '%s'\n", vm.Name) + return } } - if e := os.RemoveAll(leftover); e != nil { - log.Println(e.Error()) - } - log.Printf("successfully halted '%s'\n", vm.Name) - }() - - return + } } func init() { From c104d97e5ca77216da545feaef84ba61019d6641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Wed, 2 Dec 2015 22:00:28 +0000 Subject: [PATCH 2/4] fix logic issues on VM's boot handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... and suddently workarounds stop being needed. Signed-off-by: António Meireles --- run.go | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/run.go b/run.go index 252c9e1..8fcf00a 100644 --- a/run.go +++ b/run.go @@ -172,23 +172,39 @@ func bootVM(vipre *viper.Viper) (err error) { go func() { wg.Add(1) - defer func() { - if r := recover(); r == nil { - wg.Done() - } - }() + defer wg.Done() + if err != nil { return } - for range time.Tick(500 * time.Millisecond) { - vm.Pid = c.Process.Pid - break - } - for range time.Tick(500 * time.Millisecond) { - var e error - if vm.PublicIP, e = - uuid2ip.GuestIPfromMAC(vm.MacAddress); e == nil { + for { + select { + case <-time.After(2 * time.Second): + log.Println("Unable to grab VM's pid after 2s (!)... " + + "Aborting") + return + case <-time.Tick(100 * time.Millisecond): + vm.Pid = c.Process.Pid + } + if vm.Pid > 0 { + break + } + } + for { + select { + case <-time.After(5 * time.Second): + log.Println("Unable to grab VM's IP after 5s (!)... " + + "Aborting") + return + case <-time.Tick(250 * time.Millisecond): + var e error + if vm.PublicIP, e = + uuid2ip.GuestIPfromMAC(vm.MacAddress); e == nil { + break + } + } + if vm.PublicIP != "" { break } } From 34d90d863afc7083fc26800b45ffcaf218d2ab4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Wed, 2 Dec 2015 22:03:28 +0000 Subject: [PATCH 3/4] drop workaround for issue i'm unable to reproduce anymore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: António Meireles --- helpers.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/helpers.go b/helpers.go index 763ce86..665059e 100644 --- a/helpers.go +++ b/helpers.go @@ -37,7 +37,6 @@ import ( "strconv" "strings" "sync" - "time" "github.com/blang/semver" "github.com/mitchellh/go-ps" @@ -336,19 +335,12 @@ func (vm *VMInfo) isActive() bool { func (vm *VMInfo) metadataService() (endpoint string, err error) { var ( - free net.Listener - runOnce sync.Once - freePort = func() (net.Listener, error) { - defer recover() - return net.Listen("tcp", "localhost:0") - } + free net.Listener + runOnce sync.Once ) - // workaround OSX and/or golang weirdness... - for range time.Tick(500 * time.Millisecond) { - if free, err = freePort(); err == nil { - break - } + if free, err = net.Listen("tcp", "127.0.0.1:0"); err != nil { + return } mux := http.NewServeMux() From 50e4fa79ac7e9d795286d9d0e494795f76187942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Wed, 2 Dec 2015 22:07:57 +0000 Subject: [PATCH 4/4] let remain on fs data from problematic VMs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit anything that isn't halted (properly) via `coreos halt` is left under ~/.coreos/running/ as it eases troubleshouting Signed-off-by: António Meireles --- helpers.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/helpers.go b/helpers.go index 665059e..4bc7de6 100644 --- a/helpers.go +++ b/helpers.go @@ -311,23 +311,23 @@ func normalizeVersion(version string) string { } func (vm *VMInfo) isActive() bool { - clean := func() { - staled := filepath.Join(SessionContext.runDir, vm.UUID) - if SessionContext.debug { - log.Println("removing staled", staled) - } - - if e := os.RemoveAll(staled); e != nil { - log.Println(e) - } - } + // clean := func() { + // staled := filepath.Join(SessionContext.runDir, vm.UUID) + // if SessionContext.debug { + // log.Println("removing staled", staled) + // } + // + // if e := os.RemoveAll(staled); e != nil { + // log.Println(e) + // } + // } if vm.Pid < 1 { - clean() + // clean() return false } if p, _ := ps.FindProcess(vm.Pid); p == nil || !strings.HasPrefix(p.Executable(), "corectl") { - clean() + // clean() return false } return true