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

TP2000-1434 Prevent packaging queue race conditions #1267

Merged
merged 11 commits into from
Jul 25, 2024

Conversation

dalecannon
Copy link
Contributor

@dalecannon dalecannon commented Jul 17, 2024

TP2000-1434 Prevent packaging queue race conditions

Why

A race condition can occur during concurrent requests to create/promote/demote/process packaged workbaskets, resulting in duplicate or non-contiguous queue positions that stop the queue from functioning.

What

  • Uses select_for_update() queryset operation to lock affected packaged workbasket rows while queue position are being updated

    • Makes queue position update queries non-blocking (nowait=True), catching the raised exception if a conflicting lock is already acquired
  • Returns early without updating queue positions if the selected packaged workbasket is no longer a queue member (position=0)

  • Prevents accidental double-clicking of buttons in the packaging queue

Examples

Shared queue positions after creating packaged workbaskets

Create-packaged-workbasket.mov

Shared queue positions after repositioning packaged workbaskets

Reposition-packaged-workbaskets.mov

Invalid and inconsistent positions and processing states after processing a packaged workbasket while repositioning others

Accept-envelope.mov

Invalid and inconsistent positions and processing states after repositioning a since-removed packaged workbasket

Repositioning-removed-packaged-workbasket.mov

@dalecannon dalecannon force-pushed the TP2000-1434--packaging-queue-race-condition branch 2 times, most recently from b4849a0 to a110a9d Compare July 19, 2024 13:13
@dalecannon dalecannon force-pushed the TP2000-1434--packaging-queue-race-condition branch from a110a9d to 0a21c10 Compare July 22, 2024 10:27
@dalecannon dalecannon marked this pull request as ready for review July 22, 2024 10:38
@dalecannon dalecannon requested a review from a team as a code owner July 22, 2024 10:38
publishing/models/packaged_workbasket.py Outdated Show resolved Hide resolved
publishing/views.py Show resolved Hide resolved
Copy link
Collaborator

@paulpepper-trade paulpepper-trade left a comment

Choose a reason for hiding this comment

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

LGTM

@dalecannon dalecannon merged commit 8b2cb83 into master Jul 25, 2024
8 checks passed
@dalecannon dalecannon deleted the TP2000-1434--packaging-queue-race-condition branch July 25, 2024 13:29
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.

3 participants