aneoconsulting / ArmoniK.Core

Task manager for ArmoniK (submission, scheduling, IO data, monitoring). Implements API located in https://github.com/aneoconsulting/ArmoniK.Api
https://aneoconsulting.github.io/ArmoniK.Core/
GNU Affero General Public License v3.0
10 stars 8 forks source link

fix: agent is null when error occurs in PreProcessing #767

Closed aneojgurhem closed 2 weeks ago

aneojgurhem commented 3 weeks ago

Motivation

During TaskHandler Preprocessing, when an input data is not found, the following error is raised:

System.NullReferenceException: agent_ is null.
   at ArmoniK.Core.Common.Pollster.TaskHandler.HandleErrorInternalAsync(Exception e, TaskData taskData, Boolean resubmit, Boolean requeueIfUnavailable, CancellationToken cancellationToken) in /src/Common/src/Pollster/TaskHandler.cs:line 923
   at ArmoniK.Core.Common.Pollster.TaskHandler.HandleErrorRequeueAsync(Exception e, TaskData taskData, CancellationToken cancellationToken) in /src/Common/src/Pollster/TaskHandler.cs:line 887
   at ArmoniK.Core.Common.Pollster.TaskHandler.PreProcessing() in /src/Common/src/Pollster/TaskHandler.cs:line 702
   at ArmoniK.Core.Common.Pollster.Pollster.MainLoop(CancellationToken cancellationToken) in /src/Common/src/Pollster/Pollster.cs:line 408

Then task is requeud and creates an infinite loop. This PR aims to fix this issue.

Description

In TaskHandler HandleErrorAsync, a null check was done on the variable agent_. This variable is initialized in the function ExecuteTaskAsync which is called after PreProcessing. However, when an error occurs in PreProcessing, HandleErrorAsync is called. As agent_ is not yet initialized; it produces the aforementioned error.

In HandleErrorAsync, agent_ is needed to cancel potential child tasks. In Preprocessing, no child tasks can be created yet so if the agent is null (not yet initialized) no child tasks can be created so we do not need to perfom child tasks cancellation.

Testing

A unit test has been introduced that reproduces the issue.

Impact

Avoid infinite loops when the input data is not found during task processing. Now, tasks are clearly put in Error.

Checklist