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

Rollback db transaction when background task is interrupted #2019

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

jonahkagan
Copy link
Contributor

@jonahkagan jonahkagan commented Oct 28, 2024

Bugfix for #1990

Previously, when a task got interrupted, we let the process die immediately, which would rollback the transaction automatically.

Now, we try to reset the task, which involves clearing the task started_at timestamp and then commiting the current transaction to save that change to the db. So in order to ensure that any in-progress changes from the task itself are not committed alongside those changes, we need to rollback the current transaction and start a new one.

I updated the tests for task resetting to cover this behavior, which they previously didn't cover because they didn't use the db.

@jonahkagan jonahkagan force-pushed the jonah/fix-task-reset-rollback branch from 12b7819 to 5a2686b Compare October 28, 2024 22:14
# Each task should have run exactly once
assert sorted(results) == expected_sorted_results
# Tasks should not have run in order, since some got interrupted and reset
assert results != expected_sorted_results
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I like what this assertion is trying to test, it relies on non-deterministic timing for the tasks to get executed out of order. I couldn't think of an easy way to make this work deterministically, so to prevent flaky tests I'm removing it.

Previously, when a task got interrupted, we let the process die
immediately, which would rollback the transaction automatically.

Now, we try to reset the task, which involves clearing the task
started_at timestamp and then commiting the current transaction to save
that change to the db. So in order to ensure that any in-progress
changes from the task itself are not committed alongside those changes,
we need to rollback the current transaction and start a new one.

I updated the tests for task resetting to cover this behavior, which
they previously didn't cover because they didn't use the db.
@jonahkagan jonahkagan force-pushed the jonah/fix-task-reset-rollback branch from 5a2686b to 92c7a6a Compare October 28, 2024 22:23
Copy link
Contributor

@arsalansufi arsalansufi left a comment

Choose a reason for hiding this comment

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

Good catch!

@jonahkagan jonahkagan merged commit 4615ef9 into main Oct 29, 2024
5 checks passed
@jonahkagan jonahkagan deleted the jonah/fix-task-reset-rollback branch October 29, 2024 16:15
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.

2 participants