Skip to content

Commit

Permalink
[Messenger] Add call to gc_collect_cycles() after each message is h…
Browse files Browse the repository at this point in the history
…andled
  • Loading branch information
jwage authored and nicolas-grekas committed Oct 25, 2023
1 parent 9fb937c commit a035441
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Tests/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,25 @@ public function testFlushBatchOnStop()

$this->assertSame($expectedMessages, $handler->processedMessages);
}

public function testGcCollectCyclesIsCalledOnMessageHandle()
{
$apiMessage = new DummyMessage('API');

$receiver = new DummyReceiver([[new Envelope($apiMessage)]]);

$bus = $this->createMock(MessageBusInterface::class);

$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new StopWorkerOnMessageLimitListener(1));

$worker = new Worker(['transport' => $receiver], $bus, $dispatcher);
$worker->run();

$gcStatus = gc_status();

$this->assertGreaterThan(0, $gcStatus['runs']);
}
}

class DummyReceiver implements ReceiverInterface
Expand Down
2 changes: 2 additions & 0 deletions Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function run(array $options = []): void
// this should prevent multiple lower priority receivers from
// blocking too long before the higher priority are checked
if ($envelopeHandled) {
gc_collect_cycles();

break;
}
}
Expand Down

0 comments on commit a035441

Please sign in to comment.