Skip to content

Fix #346: Document and test the loop check before processing a message - #349

Merged
samdark merged 4 commits into
masterfrom
fix-346-processed-message-on-stop
Oct 30, 2026
Merged

samdark merged 4 commits into
masterfrom
fix-346-processed-message-on-stop

Conversation

@samdark

@samdark samdark commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #346.

The handler callback that QueueConsumer passes to adapters used to return $this->loop->canContinue() after processing the message. So when the loop stopped (for example, on SIGTERM), the callback returned false for a message that was already handled, and adapters, which treat false as "not processed", kept it and handled it again.

#340 moved the loop check before processing in both QueueConsumer::run() and QueueConsumer::listen(), so false now always means "not processed, stop". This completes the fix:

  • The loops guide said the loop is checked after each processed message. It now says the check runs before each message, and a message taken from the queue after the loop stopped goes back to the queue.
  • listen() is covered: a message processed just before the loop stops is done, and the next one is left waiting.

Adapters must not acknowledge a message when the callback returns false. The AMQP adapter's matching change, yiisoft/queue-amqp#143, should be merged together with this one. yiisoft/queue-db#35 relies on the same meaning of false and should be merged after this one.

KalimeroMK and others added 3 commits October 13, 2026 00:08
`queue:run --limit=1` over two queued messages reported one processed and left the queue empty:
`InMemoryAdapter::runExisting()` removed the message that tripped the limit even though the
callback returned `false` without handling it.

Both shipped adapters already treat `false` as "not consumed" — `queue-redis` deletes only when
the callback returned `true`, `queue-amqp` nacks with requeue otherwise — so the stub was the
outlier. Spell that contract out on `runExisting()` and `subscribe()`.
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.90%. Comparing base (265d758) to head (5d06a86).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #349      +/-   ##
============================================
+ Coverage     94.59%   94.90%   +0.30%     
  Complexity      375      375              
============================================
  Files            59       59              
  Lines           981      981              
============================================
+ Hits            928      931       +3     
+ Misses           53       50       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/QueueConsumer.php Resolved
Comment thread src/Adapter/AdapterInterface.php Resolved
…essage-on-stop

# Conflicts:
#	src/Adapter/AdapterInterface.php
#	src/QueueConsumer.php
#	tests/Unit/QueueTest.php
@samdark samdark changed the title Fix #346: Check the loop before processing a message, not after Fix #346: Document and test the loop check before processing a message Oct 29, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@samdark
samdark merged commit ab17e34 into master Oct 30, 2026
23 checks passed
@samdark
samdark deleted the fix-346-processed-message-on-stop branch October 30, 2026 15:48
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.

Handler callback cannot say "consumed" and "stop" separately

2 participants