From 07973793b816202cc35a75f4e5aafd2889cdca67 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 9 Mar 2017 21:05:34 -0800 Subject: [PATCH] Address comment --- client/alloc_runner.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/client/alloc_runner.go b/client/alloc_runner.go index 09155b44e..43071f47b 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -574,18 +574,22 @@ func (r *AllocRunner) destroyTaskRunners(destroyEvent *structs.TaskEvent) { // handleDestroy blocks till the AllocRunner should be destroyed and does the // necessary cleanup. func (r *AllocRunner) handleDestroy() { - select { - case <-r.destroyCh: - if err := r.DestroyContext(); err != nil { - r.logger.Printf("[ERR] client: failed to destroy context for alloc '%s': %v", - r.alloc.ID, err) + for { + select { + case <-r.destroyCh: + if err := r.DestroyContext(); err != nil { + r.logger.Printf("[ERR] client: failed to destroy context for alloc '%s': %v", + r.alloc.ID, err) + } + if err := r.DestroyState(); err != nil { + r.logger.Printf("[ERR] client: failed to destroy state for alloc '%s': %v", + r.alloc.ID, err) + } + + return + case <-r.updateCh: + r.logger.Printf("[ERR] client: dropping update to terminal alloc '%s'", r.alloc.ID) } - if err := r.DestroyState(); err != nil { - r.logger.Printf("[ERR] client: failed to destroy state for alloc '%s': %v", - r.alloc.ID, err) - } - case <-r.updateCh: - r.logger.Printf("[ERR] client: dropping update to terminal alloc '%s'", r.alloc.ID) } }