question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Undesired behavior via `pauseInstanceWhileRefreshing` flag

See original GitHub issue

I am using this library to refresh an OAuth2 token, and it works really well.

Unfortunately, it seems like I’m unable to get it to work exactly as I want. I want it to.

What I want is for it to pause all requests until the refresh flow completes, and retry the other failed requests that were sent before the flow was started.

The library seems to let me do one or the other, but not both.

Here’s what it looks like when I set pauseInstanceWhileRefreshing to true:

image

All of the failed requests are sent before the refresh flow is started (the reset?req=... as well as the timeout-500 one). The first one (resets?req=3) is retried after the flow completes, but the others are just dropped.

The other timeout ones are ostensibly sent wile the flow is in-progress, and those are paused until the flow completed (desired behavior).

I’d like a way to retry the pre-flow ones that failed.

Here’s what I get if I turn the flag off:

image

All of the failed requests are retried, which is exactly what I want, but also requests that are sent after the flow is started are not paused, resulting in more failed requests than necessary.

Still, the failures are hidden from the callers, which is what I want in either case, so that’s good.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
huttj-lowescommented, Sep 17, 2020

Apologies for the delay. Here’s a code sample:

createAuthRefreshInterceptor(axios, async (failedRequest) => {
  const token = Token.load();
  if (token) {
    const { data } = await axios.post(TOKEN_URL, token, {
      // eslint-disable-next-line
      // @ts-ignore
      skipAuthRefresh: true,
    });

    Token.save(data);

    failedRequest.response.config.headers.Authorization = `Bearer ${token.id_token}`;
  } else {
    throw new Error("Not logged in");
  }
});

axios.interceptors.request.use((request) => {
  const token = Token.load();
  if (token) {
    request.headers.Authorization = `Bearer ${token.id_token}`;
  }
  return request;
});

This is the configuration that works as I want it, except that it lets extra failed requests through.

If I add pauseInstanceWhileRefreshing: true to the config:

createAuthRefreshInterceptor(axios, async (failedRequest) => {
  const token = Token.load();
  if (token) {
    const { data } = await axios.post(TOKEN_URL, token, {
      // eslint-disable-next-line
      // @ts-ignore
      skipAuthRefresh: true,
    });

    Token.save(data);

    failedRequest.response.config.headers.Authorization = `Bearer ${token.id_token}`;
  } else {
    throw new Error("Not logged in");
  }
}, {
  pauseInstanceWhileRefreshing: true
});

This causes some requests to be dropped, and not retried (the if several are sent simultaneously, they all fail, but only one is retried).

0reactions
s-titovcommented, Aug 11, 2022

I have had the same problem, any solutions? 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improve the "Pause the instance while "refresh logic ... - GitHub
The pauseInstanceWhileRefreshing flag was introduced in one of the first versions of the library (when there was no skipAuthRefresh flag) to ...
Read more >
The axios-auth-refresh from Flyrell - GithubHelp
library that helps you implement automatic refresh of authorization via axios interceptors. ... Undesired behavior via `pauseInstanceWhileRefreshing` flag.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found