Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct logic in lock check to fix async mode lockup bug #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jgor
Copy link

@jgor jgor commented Aug 28, 2024

This PR fixes a bug when BACKGROUND_TASK_RUN_ASYNC=True and BACKGROUND_TASK_ASYNC_THREADS=# where # of tasks have been marked locked but are never considered unlocked due to expiration, causing all task processing to cease until the tasks are manually deleted.

locked() and unlocked() currently return conflicting sets of tasks, where certain tasks are returned by both locked() and unlocked(), due to a logic error in the query set. This leads to a state where a number of tasks equal to BACKGROUND_TASK_ASYNC_THREADS are all marked locked_by but are not running and the lock has expired, yet the count of tasks available to be run in asynchronous mode will always be non-positive which blocks further processing.

The fix is to invert the logic of locked criteria: locked_by must be present AND expires_at must be greater than locked_at. Otherwise, locked_by always takes precedent and all tasks that have been locked will remain locked indefinitely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant