Skip to content

[Bug] Fix stale queue-dispatch pending flag after synchronous dispatch - #502

Merged
kingjia90 merged 3 commits into
2026.2from
fix/queue-dispatch-stale-pending-flag
Aug 27, 2026
Merged

[Bug] Fix stale queue-dispatch pending flag after synchronous dispatch#502
kingjia90 merged 3 commits into
2026.2from
fix/queue-dispatch-stale-pending-flag

Conversation

@kingjia90

Copy link
Copy Markdown
Contributor

Problem

QueueMessagesDispatcher::dispatchQueueMessages() marks the dispatch as pending after dispatching the message. A synchronous dispatch (update:index, deployment:reindex, UpdateLanguageSettingsHandler, and the installer via the post-install command) is handled inline on the sync:// transport, and DispatchQueueMessagesHandler clears the pending state in its finally block — i.e. before markAsPending() runs. The stale flag then suppresses every save-triggered queue dispatch (messageShouldBeTriggered() returns false) for the whole TmpStore lifetime of 5 minutes. The same race exists for asynchronous dispatches when a worker consumes the message before markAsPending() executes.

Practical impact: for up to 5 minutes after generic-data-index:update:index (or a fresh pimcore-install, which runs it as post-install command), queue entries created by element saves are not dispatched — reproducible on a clean skeleton install (found while verifying Elasticsearch 8.12.2 for pimcore/internal-improvements#25: seeded elements' follow-up queue entries stayed undispatched with dispatched = 0 while the stale generic_data_index_queue_messages_dispatch_pending TmpStore entry existed).

Fix

Mark the dispatch as pending before dispatching, and clear the flag again if the dispatch itself throws. For synchronous dispatches the inline handler then clears the flag as the last step (correct end state); for asynchronous dispatches the flag can no longer race with a fast worker.

Regression test

tests/Functional/SearchIndex/QueueMessagesDispatcherTest — red on the previous code (pendingMessageExists() stayed true after a synchronous dispatch), green with the fix.

🤖 Generated with Claude Code

QueueMessagesDispatcher marked the dispatch as pending AFTER the message
bus dispatch. A synchronously dispatched DispatchQueueMessagesMessage is
handled inline (sync:// transport), and the handler clears the pending
state in its finally block - so the flag was re-created afterwards and,
with no message left to clear it, suppressed every subsequent
save-triggered queue dispatch for the whole TmpStore lifetime (5 min).
The same race exists for asynchronous dispatches when a worker handles
the message before markAsPending() runs.

Mark the dispatch as pending before dispatching and clear it again if
the dispatch itself fails.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 27, 2026 11:37
@kingjia90 kingjia90 added this to the 2026.2.7 milestone Aug 27, 2026
@kingjia90 kingjia90 self-assigned this Aug 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes stale queue-dispatch state caused by synchronous or fast asynchronous message handling.

Changes:

  • Marks dispatches pending before sending.
  • Clears pending state if dispatch throws.
  • Adds functional regression tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Service/SearchIndex/IndexQueue/QueueMessagesDispatcher.php Corrects pending-state lifecycle.
tests/Functional/SearchIndex/QueueMessagesDispatcherTest.php Adds regression coverage for synchronous dispatch.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/Functional/SearchIndex/QueueMessagesDispatcherTest.php Outdated
Comment thread src/Service/SearchIndex/IndexQueue/QueueMessagesDispatcher.php
kingjia90 and others added 2 commits August 27, 2026 13:43
…ed-dispatch rollback

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kingjia90
kingjia90 requested a balanced review from Copilot August 27, 2026 11:44
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@kingjia90
kingjia90 merged commit 162c75c into 2026.2 Aug 27, 2026
22 checks passed
@kingjia90
kingjia90 deleted the fix/queue-dispatch-stale-pending-flag branch August 27, 2026 14:42
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants