ky icon indicating copy to clipboard operation
ky copied to clipboard

Retry option is invalid for back-end server

Open yrcs opened this issue 3 years ago • 1 comments

I configured the retry option according to the document. After several attempts, i found that the retry option is only valid for front-end servers, not for back-end servers. e.g. If i take the back-end server offline, and keep the front-end server online. Even if i configured the retry option on the front-end server, but the retry still doesn't work. It did not retry to send the request to the back-end server, but only throws a TimeoutError. My front-end server is React, and my back-end server is Gin web framework.

ky.extend({
    timeout: 10000,
    retry: {
      maxRetryAfter: undefined,
    },
    hooks: {
      beforeRetry: [
        ({ error, retryCount, request }) => {
          if (error && retryCount === 2) {
            return ky.stop;
          }
          request.headers.set("Authorization", `Bearer ${token.accessToken}`);
        },
      ],
    },
})

yrcs avatar Nov 27 '21 02:11 yrcs

To be clear, you are using Ky only on the client, in a React app, is that correct? The retry option exists to automatically retry failed requests to any kind of server and it should work regardless of whether Ky is running on the client or on the server.

We have a whole suite of passing tests that verify this behavior.

Just so you know, with timeout: 10000, Ky will only retry for up to 10 seconds. And because you have maxRetryAfter: undefined, if Ky receives a response with a Retry-After header whose value is higher than 10 seconds, then the retry request will be canceled. So those are a couple of ways that retries could be broken for you.

If you need further help, we will probably need more information, including a reproducible example.

Here are some tools to help create a reproducible example:

  • https://stackblitz.com
  • https://beeceptor.com
  • https://httpbin.org
  • https://httpstat.us
  • https://codesandbox.io

sholladay avatar Feb 23 '22 08:02 sholladay