Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jonnywilliamson's avatar

Should "retry" be ignored when sending async/pool requests

Hi,

I'm currently using the Laravel Http Client extensively, and in particular async requests. One item I seem to be noticing is that when my code uses async requests, it seems to ignore the retry option.

So

Http::retry(3)->get('https://httpbin.org/headers');

Will retry correctly if there's an issue but:

Http::pool(fn (Pool $pool) => [
    $pool->retry(3)->get('https://httpbin.org/headers'),
    $pool->retry(3)->get('https://httpbin.org/headers'),
);

Does not.

Looking into the PendingRequest class I can see where I think the problem begins. Around line half way down the method in the send function, we return early with a promise if the request is to be async just before the retry code is applied to the non-async request.

 /** 
  * Send the request to the given URL. 
  * 
  * @param  string  $method 
  * @param  string  $url 
  * @param  array  $options 
  * @return \Illuminate\Http\Client\Response 
  * 
  * @throws \Exception 
  */ 
 public function send(string $method, string $url, array $options = []) 
 { 
     if (! Str::startsWith($url, ['http://', 'https://'])) { 
         $url = ltrim(rtrim($this->baseUrl, '/').'/'.ltrim($url, '/'), '/'); 
     } 

     $options = $this->parseHttpOptions($options); 

     [$this->pendingBody, $this->pendingFiles] = [null, []]; 

     if ($this->async) { 
         return $this->makePromise($method, $url, $options); 
     } 

     $shouldRetry = null; 

     return retry($this->tries ?? 1, function ($attempt) use ($method, $url, $options, &$shouldRetry) { 
         try { 

Is this intentional? Is there a reason why we can't apply the retry options to an async request. Would that force the promise to need to be resolved first before it could check and therefore negate any benefit of using an async request in the first place?

Just want to check before I go down a large rabbit hole trying to make this work, if anyone knows if this is intentional design or if it's a just something that's been missed.

Thank you.

0 likes
4 replies
jonnywilliamson's avatar

No, and it's still quite annoying.

If I get time I might try and raise it as an issue in the framework github repo.

diegocam's avatar

Noticed this as well. retry() does not work with Pool requests.

kirk_kh's avatar

+1

it's a big problem – retrying requests in pools shoold be implemented and documented

Please or to participate in this conversation.