Genesys Cloud Node SDK: Token refresh race condition during bulk API batch

Running into a weird race condition with the @genesyscloud/genesyscloud-node SDK. I’m processing a large batch of user records, making sequential calls to /api/v2/users. The access token expires halfway through the loop. The SDK handles the refresh internally via oauth2.refreshToken(), but the subsequent requests fail with a 401 Unauthorized instead of retrying with the new token.

The issue seems to be that the promise returned by the API call resolves before the refresh token fetch completes. The SDK’s interceptor sees the 401, triggers the refresh, but doesn’t seem to hold the original request in a queue. It just fails fast.

Here’s the loop:

const users = await getUsers();
for (const user of users) {
 try {
 await genesysClient.usersApi.updateUser(user.id, user);
 } catch (err) {
 console.error('Failed for user:', user.id, err.message);
 }
}

The error is 401: Unauthorized. I’ve checked the SDK source, and the retryInterceptor does check for 401s, but it looks like it’s not handling the async refresh correctly in a high-throughput loop. If I add a 5-second delay between calls, it works. That’s not a solution.

Is there a way to configure the SDK to queue requests during a token refresh? Or do I need to implement my own locking mechanism around the refresh call? I’ve seen mentions of authClient.refreshToken() being exposed, but calling it manually breaks the internal state.

Also, the error response body is empty, which makes debugging harder. Just 401. No helpful details. Anyone else hit this? I’m on v4.2.1 of the SDK.