webiny / webiny-js

Open-source serverless enterprise CMS. Includes a headless CMS, page builder, form builder, and file manager. Easy to customize and expand. Deploys to AWS.
https://www.webiny.com
Other
7.33k stars 603 forks source link

fix(api-headless-cms-tasks): race conditions while emptying the entries #4144

Closed leopuleo closed 4 months ago

leopuleo commented 4 months ago

Changes

With this PR, we aim to:

TaskCache and TaskTrigger

The main change introduced by this fix is the use of a cache to store all the subtasks created while looping through the entries that need to be deleted.

Previously, when dealing with a large number of entries, the child tasks would start executing while the main task was still executing. This could cause a race condition and lead to failures when deleting some entries that had already been deleted by other subtasks.

With this pull request, we are now storing inputs for subtasks inside an internal cache and executing them after the main task loop finishes.

How Has This Been Tested?

Manually + Jest