This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
Fix Celery deadlocks by removing all blocking tasks from parent tasks #359
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After discussing the issue at length with the helpful folks on IRC, it was confirmed that the upgrade to Celery 3.1.x made this problem much worse for us as "the pool prefetching will (now) write the tasks to the same process that is waiting".
Celery best practice is to not call blocking tasks within other tasks or risk resource starvation and deadlocking, see:
http://docs.celeryproject.org/en/latest/userguide/tasks.html#avoid-launching-synchronous-subtasks
This PR moves much of the blocking subtasks into the model methods. It has the added benefit of simplifying view/task code with a net decrease in total lines of code. While it's possible this introduced a regression, I did heavy testing with a pool of 1.