[Bug]: Removed child dependency job still has parent set on next attempt / after delay #2833
Open
1 task done
Labels
bug
Something isn't working
Version
v5.20.0
Platform
NodeJS
What happened?
If a job calls
job.removeChildDependency()
and then delays or fails, its parent will be set on the next attempt. This will cause another call tojob.removeChildDependency()
to throw an exception, if the parent job has finished.After
await job.removeChildDependency()
,job.parent
isundefined
. I'd expect it to beundefined
on the next attempt, too.To work around this, I need to (1) try...catch the call to
job.removeChildDependency
, or (2) ensure it doesn't get called twice by, for example, changing the job's data.My use case for
removeChildDependency
is to let a parent job finish, if the child job has to be delayed for a long time for some reason (in my case, it's due to resource-specific rate limits).How to reproduce.
The following code will set up a queue where the parent job schedules two child jobs. The second child job (id:
c-456
) will remove itself from the parent and then delay itself. This allows the parent job to finish.However, once the (now detached) child job runs again, its
job.parent
property will still be set to the parent job. Callingjob.removeChildDependency
would then fail, because the parent will have been removed.This is demonstrated by the log output in the next section. For the second attempt of
c-456
, it still prints(p: parent-1)
, even though the dependency was removed in the previous attempt.Relevant log output
2024-10-16T12:02:58.500Z parent parent-1 active attempt 1 2024-10-16T12:02:58.504Z child c-123 (p: parent-1) active attempt 1 2024-10-16T12:02:59.014Z child c-123 (p: parent-1) completed 2024-10-16T12:02:59.015Z child c-456 (p: parent-1) active attempt 1 2024-10-16T12:02:59.524Z parent parent-1 active attempt 2 2024-10-16T12:02:59.527Z parent parent-1 completed # In this attempt, c-456 should not have a parent 2024-10-16T12:02:59.528Z child c-456 (p: parent-1) active attempt 2 2024-10-16T12:03:00.033Z child c-456 (p: parent-1) completed
Code of Conduct
The text was updated successfully, but these errors were encountered: