Skip to content

[Messenger] [Amqp] Added missing rpc_timeout option #48612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Dec 12, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

Without this option, it's not possible to set a timeout on the connection. It
means, if the network between RabbitMQ and the application goes down, the code
in Connection::get() will hand forever. And at some point it will cause more
troubles. For example:

  • many connection/channel opened (because the consumer is not killed) ;
  • or, when the connexion gets back, RabbitMQ have killed the consumer anyway =>
    Another Exception.

With this patch, and with the following configuration, exception are clear on
what occurs.

framework:
    messenger:
        transports:
            rabbitmq:
                dsn: ....
                options:
                    read_timeout: 5
                    write_timeout: 5
                    connect_timeout: 5
                    confirm_timeout: 5
                    rpc_timeout: 5
                    [...]

Example of exception:

In AmqpReceiver.php line 56:

  [Symfony\Component\Messenger\Exception\TransportException]
  Library error: request timed out

Exception trace:
  at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:56
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getEnvelope() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:47
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getFromQueues() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:41
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->get() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Worker.php:106
 Symfony\Component\Messenger\Worker->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php:229
 Symfony\Component\Messenger\Command\ConsumeMessagesCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:1038
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:88
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:312
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:168
 Symfony\Component\Console\Application->run() at /app/bin/console:29

In Connection.php line 432:

  [AMQPException]
  Library error: request timed out

Exception trace:
  at /app/vendor/symfony/amqp-messenger/Transport/Connection.php:432
 AMQPQueue->get() at /app/vendor/symfony/amqp-messenger/Transport/Connection.php:432
 Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection->get() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:54
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getEnvelope() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:47
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getFromQueues() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:41
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->get() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Worker.php:106
 Symfony\Component\Messenger\Worker->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php:229
 Symfony\Component\Messenger\Command\ConsumeMessagesCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:1038
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:88
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:312
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:168
 Symfony\Component\Console\Application->run() at /app/bin/console:29

messenger:consume [-l|--limit LIMIT] [-f|--failure-limit FAILURE-LIMIT] [-m|--memory-limit MEMORY-LIMIT] [-t|--time-limit TIME-LIMIT] [--sleep SLEEP] [-b|--bus BUS] [--queues QUEUES] [--no-reset] [--] [<receivers>...]

@carsonbot carsonbot added this to the 5.4 milestone Dec 12, 2022
@carsonbot carsonbot changed the title [Messenger][Amqp] Added missing rpc_timeout option [Messenger] [Amqp] Added missing rpc_timeout option Dec 12, 2022
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deserves some changelog entry?

@lyrixx
Copy link
Member Author

lyrixx commented Dec 13, 2022

I don't know since it's a bugfix to me

@nicolas-grekas
Copy link
Member

Should we add a link to the doc of each options somewhere? Because I would have no idea that I'd need to set this, and what it's for.

@lyrixx
Copy link
Member Author

lyrixx commented Dec 13, 2022

To be honest, I found this in an empiric manner :)

Some ref: https://github.com/php-amqp/php-amqp/blob/master/stubs/AMQPConnection.php#L33-L36

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the link to the source phpdoc that lists options please?

Without this option, it's not possible to set a timeout on the connection. It
means, if the network between RabbitMQ and the application goes down, the code
in `Connection::get()` will hand forever. And at some point it will cause more
troubles. For example:

* many connection/channel opened (because the consumer is not killed) ;
* or, when the connexion gets back, RabbitMQ have killed the consumer anyway =>
  Another Exception.

With this patch, and with the following configuration, exception are clear on
what occurs.

```
framework:
    messenger:
        transports:
            rabbitmq:
                dsn: ....
                options:
                    read_timeout: 5
                    write_timeout: 5
                    connect_timeout: 5
                    confirm_timeout: 5
                    rpc_timeout: 5
                    [...]
```

Example of exception:

```
In AmqpReceiver.php line 56:

  [Symfony\Component\Messenger\Exception\TransportException]
  Library error: request timed out

Exception trace:
  at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:56
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getEnvelope() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:47
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getFromQueues() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:41
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->get() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Worker.php:106
 Symfony\Component\Messenger\Worker->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php:229
 Symfony\Component\Messenger\Command\ConsumeMessagesCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:1038
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:88
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:312
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:168
 Symfony\Component\Console\Application->run() at /app/bin/console:29

In Connection.php line 432:

  [AMQPException]
  Library error: request timed out

Exception trace:
  at /app/vendor/symfony/amqp-messenger/Transport/Connection.php:432
 AMQPQueue->get() at /app/vendor/symfony/amqp-messenger/Transport/Connection.php:432
 Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection->get() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:54
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getEnvelope() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:47
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->getFromQueues() at /app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:41
 Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver->get() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Worker.php:106
 Symfony\Component\Messenger\Worker->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php:229
 Symfony\Component\Messenger\Command\ConsumeMessagesCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:1038
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:88
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:312
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:168
 Symfony\Component\Console\Application->run() at /app/bin/console:29

messenger:consume [-l|--limit LIMIT] [-f|--failure-limit FAILURE-LIMIT] [-m|--memory-limit MEMORY-LIMIT] [-t|--time-limit TIME-LIMIT] [--sleep SLEEP] [-b|--bus BUS] [--queues QUEUES] [--no-reset] [--] [<receivers>...]

```
@nicolas-grekas
Copy link
Member

I added a link to https://github.com/php-amqp/php-amqp/blob/master/amqp_connection_resource.h
Which lists also sasl_method and connection_name BTW.

@nicolas-grekas
Copy link
Member

Thank you @lyrixx.

@nicolas-grekas nicolas-grekas merged commit 70b403d into symfony:5.4 Dec 13, 2022
@lyrixx lyrixx deleted the messenger-timeout branch December 14, 2022 02:09
@fabpot fabpot mentioned this pull request Dec 16, 2022
This was referenced Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants