From d5400c435879be48301e1724facb27c46cbe7d85 Mon Sep 17 00:00:00 2001 From: Albertin Loic Date: Fri, 11 Jun 2021 11:06:55 +0200 Subject: [PATCH] Use context on consul query options This will allow the underlying http request to handle context cancellation and release the connection as soon as the local execution is done not after an http timeout --- CHANGELOG.md | 1 + tasks/tasks.go | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a81cb94b..2dc038044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### BUG FIXES +* Over-consumption of Consul connections ([GH-745](https://github.com/ystia/yorc/issues/745)) * Yorc panics attempting to print an error handling a script execution stdout ([GH-741](https://github.com/ystia/yorc/issues/741)) * Error submitting a SLURM job with no execution option ([GH-739](https://github.com/ystia/yorc/issues/739)) diff --git a/tasks/tasks.go b/tasks/tasks.go index 481d46608..05b43f496 100644 --- a/tasks/tasks.go +++ b/tasks/tasks.go @@ -625,15 +625,11 @@ func MonitorTaskFailure(ctx context.Context, taskID string, f func()) { func monitorTaskFlag(ctx context.Context, taskID, flag string, value []byte, f func()) { go func() { var lastIndex uint64 + queryMeta := &api.QueryOptions{} + queryMeta = queryMeta.WithContext(ctx) for { - select { - case <-ctx.Done(): - log.Debugf("Task monitoring for flag %s exit", flag) - return - default: - } - - kvp, qMeta, err := consulutil.GetKV().Get(path.Join(consulutil.TasksPrefix, taskID, flag), &api.QueryOptions{WaitIndex: lastIndex}) + queryMeta.WaitIndex = lastIndex + kvp, qMeta, err := consulutil.GetKV().Get(path.Join(consulutil.TasksPrefix, taskID, flag), queryMeta) select { case <-ctx.Done():