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] The acknowledger was not called in batch handler #59734

Copy link
Copy link
Open
@MartkCz

Description

@MartkCz
Issue body actions

Symfony version(s) affected

Description

SplObjectStorage should not be iterated with foreach if unset is called inside the loop.

https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/Messenger/Worker.php#L273-L282

If I run the following code with two different messages handled by two batch handlers, the exception 'The acknowledger was not called in ...' is thrown.

$eventDispatcher->addListener(WorkerRunningEvent::class, function workerRunning(WorkerRunningEvent $event): void {
  if ($event->isWorkerIdle()) {
    $event->getWorker()->stop();
  }
});

$worker = new Worker($receivers, $this->routableBus, $this->eventDispatcher, $this->logger, $rateLimiters);
$options = ['sleep' => 0];

$worker->run($options);

Probably related to #54600 ?

How to reproduce

$storage = new SplObjectStorage();

$first = new stdClass();
$first->name = 'first';
$storage->attach($first);

$second = new stdClass();
$second->name = 'second';
$storage->attach($second);

foreach ($storage as $item) { // prints "first"
  echo $item->name . PHP_EOL;

  unset($storage[$item]);
}

echo sprintf('Count: %d' . PHP_EOL, $storage->count()); // prints "Count: 1"

https://onlinephp.io/c/40e1a

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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