Open ELanning opened 3 years ago
I don't think retrying is the way to go, but we should be able to fetch a new access token a few seconds before it expires to avoid this.
Here's the relevant code
That seems like it might mitigate the issue enough 👍
Of course if there's a lot of active Promises
I don't know if it will get the opportunity to renew the token within that small buffer time, but I don't know if this is an issue in practice or how the internals of V8 work so this may be a non-issue.
Hypothesis: There could be a race condition where a request happens in-between a refresh interval. This could cause a 401 issue such as this.
For example, a request to get a subreddit
1ms
before the access token is due to be expired, thus it expires midflight.Solution: Handle these errors for the consumer of the API? If a
401
occurs, try to fetch a new access token once or twice before throwing a 401 error?I am not entirely sure this is the issue as I only spent a few hours debugging, but it seems like it could be an issue in-general.
Additional info: happens sporadically with both auth methods (eg refresh_token or username/password).