adutra commented on code in PR #18910:
URL: https://github.com/apache/iceberg/pull/18910#discussion_r4549393069
##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
@@ -499,6 +499,7 @@ public static AuthSession empty() {
*/
public Pair<Integer, TimeUnit> refresh(RESTClient client) {
if (token() != null && config.keepRefreshed()) {
+ long startTimeMillis = System.currentTimeMillis();
Review Comment:
`startTimeMillis` is captured before the `Tasks.foreach` retry loop, but
`expires_in` counts from when the server issued the token. With exponential
backoff (up to 30 min total), the stored expiry gets shifted earlier by the
whole retry duration. It errs on the safe side, but the value is inaccurate.
Could we take the timestamp per attempt, inside the lambda, so it only
reflects the successful request?
##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
Review Comment:
Isn't the else branch unreachable now? The only way to reach that branch is
a refreshed token with no `exp` claim and a response with no `expires_in`, and
that case returns a null `expiration`.
##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2110,9 +2110,11 @@ public void
testCatalogTokenRefreshFailsAndUsesCredentialForRefresh(String oauth
any(),
any());
- // verify the first token exchange - since an exception is
thrown, we're performing
- // retries
- Mockito.verify(adapter, times(2))
+ // verify the first token exchange. The exchange throws and is
retried, but the
+ // session knows the token expires 1s after it was issued (from
expires_in), so the
Review Comment:
Previously this was deterministic: expiry was unknown for opaque tokens, so
the retry always repeated the normal exchange (hence `times(2)`).
Now the outcome depends on whether the retry (100ms + 0–9ms jitter) lands
after the 1s expiry, and the margin is only a few ms, since the refresh is
scheduled ~100ms before expiry.
It seems that, if the retry lands early, a second exchange with the old
token could happen, and `verify(adapter)` could fail. Could we use a larger
`expires_in`, or assert only that the credential-based exchange eventually
happens?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]