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

Fix new scheduled tasks jumping the queue #17962

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

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Nov 26, 2024

Currently, when a new scheduled task is added and its scheduled time has already passed, we set it to ACTIVE. This is problematic, because it means it will jump the queue ahead of all other SCHEDULED tasks; furthermore, if the Synapse process gets restarted, it will jump ahead of any ACTIVE tasks which have been started but are taking a while to run.

Instead, we leave it set to SCHEDULED, but kick off a call to _launch_scheduled_tasks, which will decide if we actually have capacity to start a new task, and start the newly-added task if so.

@richvdh richvdh requested a review from a team as a code owner November 26, 2024 13:12
Comment on lines -129 to -130
# We need to wait for the next run of the scheduler loop
self.reactor.advance((TaskScheduler.SCHEDULE_INTERVAL_MS / 1000))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this hasn't actually changed, I'm just tightening up the test a bit. We didn't need to wait for the next run of the loop, we just had to wait 0.1 seconds. Looks like this changed in matrix-org/synapse#16313 and matrix-org/synapse#16660 without the test being updated.

Currently, when a new scheduled task is added and its scheduled time has
already passed, we set it to ACTIVE. This is problematic, because it means it
will jump the queue ahead of all other SCHEDULED tasks; furthermore, if the
Synapse process gets restarted, it will jump ahead of any ACTIVE tasks which
have been started but are taking a while to run.

Instead, we leave it set to SCHEDULED, but kick off a call to
`_launch_scheduled_tasks`, which will decide if we actually have capacity to
start a new task, and start the newly-added task if so.
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