tr: stop stats collection on Exited hook

This commit is contained in:
Nick Ethier 2019-01-14 12:30:14 -05:00
parent a4534779d3
commit fbd403df96
No known key found for this signature in database
GPG key ID: 07C1A3ECED90D24A

View file

@ -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)