8000 [Messenger] MultiplierRetryStrategy - Return value must be of type int, float returned · Issue #46795 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] MultiplierRetryStrategy - Return value must be of type int, float returned #46795

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

Closed
WissameMekhilef opened this issue Jun 28, 2022 · 0 comments

Comments

@WissameMekhilef
Copy link
Contributor
WissameMekhilef commented Jun 28, 2022

Symfony version(s) affected

6.1

Description

The MultiplierRetryStrategy multiplies a float with an integer which results in a float, however, the function expects an int.

This causes the code to fail.

How to reproduce

messenger.yaml

fifo:
    dsn: '%env(DSN_OF_SQS_FIFO_QUEUE)%'
    retry_strategy:
        delay: 0 # This is necessary as per the Symfony documentation

Fail a message with a RecoverableExceptionInterface, and you should get the failure Symfony\Component\Messenger\Retry\MultiplierRetryStrategy::getWaitingTime(): Return value must be of type int, float returned

Possible Solution

The issue is here in the code \Symfony\Component\Messenger\Retry\MultiplierRetryStrategy::getWaitingTime

We could round up or down the $delay before sending it back, that way the interface is preserved.

Additional Context

Exception

{
   "class":"TypeError",
   "message":"Symfony\\Component\\Messenger\\Retry\\MultiplierRetryStrategy::getWaitingTime(): Return value must be of type int, float returned",
   "code":0,
   "file":"/application/vendor/symfony/messenger/Retry/MultiplierRetryStrategy.php:89",
   "trace":[
      "/application/vendor/symfony/messenger/EventListener/SendFailedMessageForRetryListener.php:70",
      "/application/vendor/symfony/event-dispatcher/EventDispatcher.php:270",
      "/application/vendor/symfony/event-dispatcher/EventDispatcher.php:230",
      "/application/vendor/symfony/event-dispatcher/EventDispatcher.php:59",
      "/application/vendor/symfony/messenger/Worker.php:192",
      "/application/vendor/symfony/messenger/Worker.php:168",
      "/application/vendor/symfony/messenger/Worker.php:105",
      "/application/vendor/symfony/messenger/Command/ConsumeMessagesCommand.php:223",
      "/application/vendor/symfony/console/Command/Command.php:298",
      "/application/vendor/symfony/console/Application.php:1042",
      "/application/vendor/symfony/framework-bundle/Console/Application.php:94",
      "/application/vendor/symfony/console/Application.php:299",
      "/application/vendor/symfony/framework-bundle/Console/Application.php:80",
      "/application/vendor/symfony/console/Application.php:171",
      "/application/bin/console:38"
   ]
}```
@WissameMekhilef WissameMekhilef changed the title Messenger Component - MultiplierRetryStrategy - Return value must be of type int, float returned [Messenger] - MultiplierRetryStrategy - Return value must be of type int, float returned Jun 28, 2022
@WissameMekhilef WissameMekhilef changed the title [Messenger] - MultiplierRetryStrategy - Return value must be of type int, float returned [Messenger] MultiplierRetryStrategy - Return value must be of type int, float returned Jun 28, 2022
nicolas-grekas added a commit that referenced this issue Jun 29, 2022
…n retry (WissameMekhilef)

This PR was submitted for the 6.1 branch but it was squashed and merged into the 4.4 branch instead.

Discussion
----------

[Messenger] Ceil waiting time when multiplier is a float on retry

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #46795
| License       | MIT
| Doc PR        | Not required

In the Messenger - MultiplierRetryStrategy the return type for the function `getWaitingTime` is int, however with the computation of that function we were returning a float, this is because float * int returns a float and the attribute $multiplier is a float.

With this fix, we are rounding up the delay and casting into an int.

Commits
-------

3b62a06 [Messenger] Ceil waiting time when multiplier is a float on retry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0