Skip to content

[HttpClientBundle] RetryableHttpClient invalid delay  #47430

@martkop26

Description

@martkop26

Symfony version(s) affected

6.1.4

Description

The Symfony RetryableHttpClient defines the $delay variable by calling $this->getDelayFromHeader($context->getHeaders()).
According to the RFC this header should be A non-negative decimal integer indicating the seconds to delay after the response is received. By directly casting the value to integer, we lose the decimal value, resulting in an invalid delay.

How to reproduce

Use the Symfony HTTP Client package.
Use the RetryableHttpClient in combination with an API which returns a HTTP code causing the RetryableHttpClient to retry.
Make sure the API returns the header 'retry-after' with a decimal value, e.g. 0.63.

The expected result will be the $delay variable to be 630.
The actual result is the $delay variable to be 0

Possible Solution

Rewrite line 141 of the Symfony\Component\HttpClient\RetryableHttpClient
from return (int) $after * 1000; to return (int) ($after * 1000);

Additional Context

Test showing the issue

http_client_original

The same test with the changed line in the RetryableHttpClient

http_client_fix

In both cases, the header retry-after returned a value of 0.70

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions