Php-amqplib: Channel gets stuck if user `wait_for_pending_acks`

Created on 26 Jul 2019  路  2Comments  路  Source: php-amqplib/php-amqplib

Guys,

I found a potential bug, but I am surprised that no one here has mentioned about it before. It looks to be a often used feature, so I may be using it in the wrong way.

I am calling wait_for_pending_acks channel method right after calling basic_publish.

$this->Channel->basic_publish($msg, $exchangeName);
$this->Channel->wait_for_pending_acks(2);

However, the service was getting stuck when the queue was blocked.

I review the code under the wait_for_pending_ackss hood and I found it:

        while (count($this->published_messages) !== 0) {
            if ($timeout > 0) {
                $this->wait($functions, true, $timeout);
            } else {
                $this->wait($functions);
            }
        }

Going deeper into wait method:

    public function wait($allowed_methods = null, $non_blocking = false, $timeout = 0)
    {
        $this->debug->debug_allowed_methods($allowed_methods);

        $deferred = $this->process_deferred_methods($allowed_methods);
        if ($deferred['dispatch'] === true) {
            return $this->dispatch_deferred_method($deferred['queued_method']);
        }

        // timeouts must be deactivated for non-blocking actions
        if (true === $non_blocking) {
            $timeout = null;
        }

As you can see, no matter which value I pass as $timeout, it will be changed to null by wait method because it always pass true as $non_blocking argument.

I changed the second argument passed by wait and it worked. But I don't know what it implies to the rest of the process.

How to reproduce

  1. Start a RabbitMQ service using very low memory (use RABBITMQ_VM_MEMORY_HIGH_WATERMARK=10MiB https://hub.docker.com/_/rabbitmq)
  2. Publish messages to that queue until your connection gets 'Blcoked` satus
    image

Expected

wait_for_pending_acks methods throw an error after N seconds

Result

wait_for_pending_acks stucks until RabbitQM connection gets unblocked OR the connection be interrupted.

bug

Most helpful comment

Fixed by #733

All 2 comments

Hi @rubens21, thanks for reporting. Looks like yes, functions wait_for_pending_acks and wait_for_pending_acks_returns incorrectly calls wait(). Should be quite high CPU usage in Your case.

Fixed by #733

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guillerial picture guillerial  路  6Comments

tugrul picture tugrul  路  3Comments

azngeek picture azngeek  路  7Comments

maprokopiou picture maprokopiou  路  4Comments

MaxwellZY picture MaxwellZY  路  5Comments