Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Open
wants to merge 2 commits into
base: 6.4
Choose a base branch
Loading
from

Conversation

ehoutsma
Copy link

@ehoutsma ehoutsma commented Oct 2, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

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.

@carsonbot
Copy link

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:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

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!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title Bug: Second batch handler worker returns "The acknowledger was not called by the ... batch handler." [Messenger] Bug: Second batch handler worker returns "The acknowledger was not called by the ... batch handler." Oct 2, 2024
@OskarStark OskarStark changed the title [Messenger] Bug: Second batch handler worker returns "The acknowledger was not called by the ... batch handler." [Messenger] Second batch handler worker returns "The acknowledger was not called by the ... batch handler." Oct 2, 2024
} catch (\Throwable $e) {
$this->acks[] = [$transportName, $envelope, $e];
}
$unacks->next();
$unacks->detach($batchHandler);
Copy link
Member

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?

Copy link
Author

@ehoutsma ehoutsma Oct 3, 2024

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.

Copy link
Author

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.

@rairlie
Copy link

rairlie commented Jan 24, 2025

I've also encountered this issue, and use a similar fix locally.

As @ehoutsma says, the problem is simply that $unacks is modified within the loop, messing up the iteration:

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:

object(stdClass)#1 (1) {
  ["val"]=>
  int(1)
}

@ehoutsma
Copy link
Author

ehoutsma commented Apr 9, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.