ForceRefresh refreshes the access token if the current token is still equal to oldToken. The oldToken parameter should be the token value observed by the caller when it determined that a refresh might be needed; if the token has changed since then, another goroutine has already refreshed it and this
(oldToken string)
| 228 | // that a refresh might be needed; if the token has changed since then, another goroutine has |
| 229 | // already refreshed it and this method returns without performing a redundant refresh. |
| 230 | func (tp *TokenProvider) ForceRefresh(oldToken string) errors.Error { |
| 231 | tp.mu.Lock() |
| 232 | defer tp.mu.Unlock() |
| 233 | |
| 234 | // If the token has changed since the request was made, it means another thread |
| 235 | // has already refreshed it. |
| 236 | if tp.conn.Token != oldToken { |
| 237 | if tp.logger != nil { |
| 238 | tp.logger.Info("Skipping reactive token refresh for connection %d — token already changed by another goroutine", tp.conn.ID) |
| 239 | } |
| 240 | return nil |
| 241 | } |
| 242 | |
| 243 | if tp.logger != nil { |
| 244 | tp.logger.Info("Reactive token refresh triggered for connection %d (received 401)", tp.conn.ID) |
| 245 | } |
| 246 | return tp.refreshToken() |
| 247 | } |