8000 [Messenger] The acknowledger was not called in batch handler · Issue #59734 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Messenger] The acknowledger was not called in batch handler #59734
Open
@MartkCz

Description

@MartkCz

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

      0