As stated in the title, I’m looking for a solution to handle access token refresh requests.
The issue is that if multiple requests come in at the same time to create a meeting, and the access token is expired, a refresh request will be sent. Multiple calls to refresh the token will result in a failure because the first request will invalidate the others aka ‘race condition’.
I’ve read several posts on here without any good solution being provided.
My thought is to, after authorization and a exchange for access token:
store the access token, expiry time, and refresh token in a database (for scalability).
On an API call, fetch info from step 1. If not expired, use it.
If expired, set a flag on the table to indicate refresh is in progress. If flag is set, wait 1 second and query again.
Customer should see a “Save Access token into Database” error message when there are duplicate requests ‘oauth/token’. Those requests need to wait the first request completed.
I suggest the customer build a flag which can indicate if the new access token is in process, when the first request finds the access token is expired, then try to get the new access token.
Meanwhile it can make the value of flag “is true” (the default value is false), then the value is revised to false after the access token is successfully retrieved. In the process, the other request needs to wait.