[7.x] Fix bulk operation queue deadlock under a flood of webhooks - #226
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The concurrency fix is covered by targeted regression tests and the schema/migration updates appear consistent with the new Failed status behavior.
Pull request overview
This PR addresses a bulk operation queue deadlock that can occur under a heavy influx of webhooks by making bulk-operation state transitions race-safe, ensuring FIFO processing under backlog, and adding a “failed” terminal state for truly stuck operations.
Changes:
- Serialize bulk-operation “check-then-act” transitions using a shared Craft mutex in
nextBulkOperation()andqueueNextBulkOperation(), and process the oldest queued/created-first items (FIFO) to prevent starvation. - Fix
saveBulkOperation()so new operations without anidand without ashopifyIddo not collide/overwrite existing rows. - Add a
Failedbulk-operation status plus migration/translation coverage, and purge logic to mark long-stuckcreated/processingrows as failed.
File summaries
| File | Description |
|---|---|
src/services/BulkOperations.php |
Adds mutex guarding + FIFO selection, fixes save lookup to avoid NULL collisions, and introduces purge behavior for stuck/terminal rows. |
src/jobs/ProcessBulkOperationData.php |
Ensures after() first queues any already-created-with-URL operation before attempting to start a new queued op. |
src/enums/BulkOperationStatus.php |
Adds Failed enum case and renders it consistently in label helpers. |
src/migrations/m260908_080800_add_failed_status_to_bulk_operations.php |
Expands DB enum values to include failed for existing installs. |
src/migrations/Install.php |
Ensures fresh installs include the failed status in the enum column definition. |
src/Plugin.php |
Bumps schema version to apply the new migration. |
src/translations/en/shopify.php |
Adds the Failed translation string used by status labels. |
tests/unit/services/BulkOperationsTest.php |
Adds regression tests for NULL-shopifyId collisions, mutex acquisition bailouts, FIFO processing, guard query shape, and purge behavior. |
tests/unit/jobs/ProcessBulkOperationDataTest.php |
Adds regression coverage to ensure after() unblocks stuck created ops with URLs by queueing them. |
tests/unit/enums/BulkOperationStatusTest.php |
Ensures all enum cases have labels/colors and explicitly covers the new Failed case. |
CHANGELOG.md |
Documents the fix, new status, and mutex constant. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Related issues
#224