From cee0e277670c5f5e9a154ddc55671ea06b3ffd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 8 Aug 2018 10:48:11 +0200 Subject: [PATCH] fix(hatchery): context cancellation --- sdk/hatchery/hatchery.go | 3 +-- sdk/hatchery/starter.go | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sdk/hatchery/hatchery.go b/sdk/hatchery/hatchery.go index 882dac4160..0770603fb9 100644 --- a/sdk/hatchery/hatchery.go +++ b/sdk/hatchery/hatchery.go @@ -280,6 +280,7 @@ func Create(h Interface) error { workerRequest := workerStarterRequest{ ctx: currentCtx, + cancel: endTrace, id: j.ID, isWorkflowJob: true, execGroups: j.ExecGroups, @@ -307,7 +308,6 @@ func Create(h Interface) error { temptToSpawn: true, } endTrace("no model or service ratio reached") - continue } @@ -317,7 +317,6 @@ func Create(h Interface) error { //Ask to start log.Info("hatchery> Request a worker for job %d (%.3f seconds elapsed)", j.ID, time.Since(t0).Seconds()) workersStartChan <- workerRequest - endTrace("") case err := <-errs: log.Error("%v", err) diff --git a/sdk/hatchery/starter.go b/sdk/hatchery/starter.go index 285f0998ac..85ab15cf46 100644 --- a/sdk/hatchery/starter.go +++ b/sdk/hatchery/starter.go @@ -13,6 +13,7 @@ import ( type workerStarterRequest struct { ctx context.Context + cancel func(reason string) id int64 isWorkflowJob bool model sdk.Model @@ -70,6 +71,12 @@ func workerStarter(h Interface, jobs <-chan workerStarterRequest, results chan<- results <- res end() + if err != nil { + j.cancel(err.Error()) + } else { + j.cancel("") + } + } else { // Start a worker for registering log.Debug("Spawning worker for register model %s", m.Name) if atomic.LoadInt64(&nbWorkerToStart) > int64(h.Configuration().Provision.MaxConcurrentProvisioning) {