-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Second batch handler worker returns "The acknowledger was not called by the ... batch handler." #58433
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
base: 6.4
Are you sure you want to change the base?
Conversation
…th unacked messages.
…th unacked messages. Unit test improvement.
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
} catch (\Throwable $e) { | ||
$this->acks[] = [$transportName, $envelope, $e]; | ||
} | ||
$unacks->next(); | ||
$unacks->detach($batchHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that we now don't call the destructor of the $batchHandler (if any) inside the try/catch.
Is that the fix or a regression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review.
The fix is that we unset the batchHandler after we set the iterator to the next batchHandler. Before it would unset the current batchHandler, and then tries to proceed to the next batchHandler but can't find the current index because it was unset.
See this comment: https://www.php.net/manual/en/splobjectstorage.detach.php#97644
Catching a Throwable of the unset, has nothing to do with the handling of the batch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas Do you have enough information to accept this PR or do you need more information. It would help us a lot if this bug is fixed.
I've also encountered this issue, and use a similar fix locally. As @ehoutsma says, the problem is simply that foreach ($unacks as $batchHandler) {
...
try {
...
unset($unacks[$batchHandler], $batchHandler); // <<-- $unacks modified while being iterated
} catch (\Throwable $e) {
...
}
} Working example: $handler1 = new stdClass();
$handler1->val = 1;
$handler2 = new stdClass();
$handler2->val = 2;
$unacks = new SplObjectStorage();
$unacks->attach($handler1);
$unacks->attach($handler2);
foreach ($unacks as $handler) {
var_dump($handler);
unset($unacks[$handler]);
} Results in only one handler being processed:
|
I understand this issue doesn't occur with a lot of users. Leaving this issue unsolved, makes the use of batchhandling with multiple batchhandlers on the same queue unreliable. @nicolas-grekas, Is it possible to merge this issue, since this is an issue that is still available even in version 7 of symfony? |
When using multiple Batch handlers, the situation can occur that there are multiple batch handlers that have messages that aren't processed and therefor not acked yet. The issue is caused by a optimalization that unsets the current batch handler in a foreach loop.
"The acknowledger was not called by the ... batch handler." is thrown when a worker is stopped and the batch isn't handled.
The issue is reproducable and testable with the attached unit test.