From 091cdbcb126aa5533a86b95bc2d00fffa9747c7f Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Mon, 14 Jan 2019 12:30:14 -0500 Subject: [PATCH] tr: stop stats collection on Exited hook --- client/allocrunner/taskrunner/stats_hook.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/allocrunner/taskrunner/stats_hook.go b/client/allocrunner/taskrunner/stats_hook.go index 867c527c7..1b93feec7 100644 --- a/client/allocrunner/taskrunner/stats_hook.go +++ b/client/allocrunner/taskrunner/stats_hook.go @@ -54,7 +54,12 @@ func (h *statsHook) Poststart(ctx context.Context, req *interfaces.TaskPoststart h.cancel() } - ctx, cancel := context.WithCancel(ctx) + // Using a new context here because the existing context is for the scope of + // the Poststart request. If that context was used, stats collection would + // stop when the task was killed. It makes for more readable code and better + // follows the taskrunner hook model to create a new context that can be + // canceled on the Exited hook. + ctx, cancel := context.WithCancel(context.Background()) h.cancel = cancel go h.collectResourceUsageStats(ctx, req.DriverStats)