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.

Improve the "Pause the instance while "refresh logic" is running" section of the docs

See original GitHub issue

Link to section: https://github.com/Flyrell/axios-auth-refresh#pause-the-instance-while-refresh-logic-is-running image

The description of the pauseInstanceWhileRefreshing parameter is not really clear. At first glance, it seems that this parameter is needed to indicate whether requests should be queued if refreshing is already in progress, but this is not the case. We had to investigate the source code to understand whether we need to use this parameter or not. It would be great to add some use cases with description when and why it might be needed.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:15
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Flyrellcommented, Sep 17, 2021

@guilliamxavier Sure, I see the point you’re making. What I mean by “no call” is to literally have no HTTP call inside it (I guess there was not a single use case for that 😅), but now when I think about it, it’s not useful anymore for whatever reason. The “no call” I mentioned does not make sense at all, as if there’s “no call”, the refreshing logic would never trigger an interceptor again - so, my bad.

TL;DR;

There is a couple of ways you can prevent the infinite loop right now:

  1. use skipAuthRefresh in your refreshing call’s configuration
createAuthRefreshInterceptor(axiosInstance, failedRequest => {
    return axiosInstance.post('/', {}, { skipAuthRefresh: true }).then(/* ... */);
});
  1. use different instance for your refreshing call
createAuthRefreshInterceptor(instance1, failedRequest => {
    return instance2.post('/', {}).then(/* ... */);
});

There’s not a single use case I can think of, that would need the pauseInstanceWhileRefreshing flag anymore.


The pauseInstanceWhileRefreshing flag was introduced in one of the first versions of the library (when there was no skipAuthRefresh flag) to prevent the instance from getting into the infinite loop (back then it was called skipWhileRefresh). It was ensuring that when the refreshingLogic is resolving, the library (specifically, response interceptor) would ignore any error originating from the instance provided in createAuthRefreshInterceptor (so that this logic is not called again as that error could have been the result of refreshing logic itself which would create the infinite loop). This might sound weird, but it was useful for a while, when the axios v0.19.0 was published and they’ve accidentally removed the possibility to pass the custom property into your request config. Fortunately, axios team did fix it in next versions, and I added the skipAuthRefresh flag to the library, which made pauseInstanceWhileRefreshing useless. After all, this is not useful anymore whatsoever, if you choose to implement the refreshing logic in one of the ways I mentioned above.

Back then I haven’t really think about using the second instance for refreshing as you suggested, and to be honest, it would definitely make more sense. I guess in the future versions I might even change ‘the API’, so that the library works more developer-friendly, as we can probably do a lot by working with multiple instances. We’ll see. However, thank you for taking your time and contributing.

0reactions
guilliamxaviercommented, Sep 17, 2021

After updating to v3.2.0 and testing a bit, I come to the conclusion that I must not use pauseInstanceWhileRefreshing: even without it I don’t see extra refresh calls (so it doesn’t seem useful), and with it the /bar and /qux failed requests are not retried after /foo (so it seems harmful)…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delay the next action in workflows - Azure Logic Apps
Wait to run the next action in logic app workflows by using the Delay or Delay Until actions in Azure Logic Apps.
Read more >
UpdatePolicy attribute - AWS CloudFormation
Specifies whether an Auto Scaling group and the instances it contains are replaced during an update. During replacement, CloudFormation retains the old ...
Read more >
System update sets - Product Documentation | ServiceNow
An update set is a group of configuration changes that can be moved from one instance to another. This feature allows administrators to ......
Read more >
How a web session is defined in Universal Analytics
The calculations don't apply if you're collecting data using an Analytics SDK for a ... Bob leaves open a page while he takes...
Read more >
Memory refresh - Wikipedia
Memory refresh is the process of periodically reading information from an area of computer memory and immediately rewriting the read information to the...
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