From b959d9831c8b8320eb7ae0f83fb253defdc6bcbc Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 27 Nov 2018 16:50:42 -0800 Subject: [PATCH] add nil check around task resources in device hook Looking at NewTaskRunner I'm unsure whether TaskRunner.TaskResources (from which req.TaskResources is set) is intended to be nil at times or if the TODO in NewTaskRunner is intended to ensure it is always non-nil. --- client/allocrunner/taskrunner/device_hook.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/allocrunner/taskrunner/device_hook.go b/client/allocrunner/taskrunner/device_hook.go index a1e09bc2e..3d55aba07 100644 --- a/client/allocrunner/taskrunner/device_hook.go +++ b/client/allocrunner/taskrunner/device_hook.go @@ -30,7 +30,9 @@ func (*deviceHook) Name() string { } func (h *deviceHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartRequest, resp *interfaces.TaskPrestartResponse) error { - if len(req.TaskResources.Devices) == 0 { + //TODO Can the nil check be removed once the TODO in NewTaskRunner + // where this is set is addressed? + if req.TaskResources == nil || len(req.TaskResources.Devices) == 0 { resp.Done = true return nil }