sroze/messenger-enqueue-transport

Time limit not being checked if no messages are being received

Closed this issue · 1 comments

skck commented

When starting a consumer with a time limit, it will only be checked after messages have been received, so the consumer will not stop after the timeout when there are no messages.

I've started the worker like this:

$ bin/console messenger:consume-messages test --time-limit=1

Then there will be an infinite loop in https://github.com/php-enqueue/messenger-adapter/blob/master/QueueInteropTransport.php#L72:

      while (!$this->shouldStop) {
            try {
                if (null === ($message = $consumer->receive($this->options['receiveTimeout'] ?? 0))) {
                    continue;
                }
                // ...
      }

When taking a look at Symfony\Component\Messenger\Transport\AmqpExt\AmqpReceiver::receive, triggering the handler with null should fix this, like:

      while (!$this->shouldStop) {
            try {
                if (null === ($message = $consumer->receive($this->options['receiveTimeout'] ?? 0))) {
                    $handler(null);
                    continue;
                }
                // ...
      }

Reference: https://github.com/symfony/messenger/blob/v4.1.0/Transport/AmqpExt/AmqpReceiver.php#L43

sroze commented

Yep, I agree. Would you like to PR the change? :)