Repository navigation
feat(java): Add Auto Refresh - #13
Conversation
62dd1e6 to
e6c14ef
Compare
|
Done |
| } | ||
| install(token, issuedAt); | ||
| refresh.complete(token); | ||
| } catch (RuntimeException exception) { |
There was a problem hiding this comment.
This only catches RuntimeException, if provider.getToken() throws an Error (e.g. NoClassDefFoundError from a classpath mismatch), this catch doesn't fire and the future is never completed, so inFlight stays set and every later getToken() hangs in join(). On the executor thread it's also swallowed silently: ScheduledFuture captures it and we discard that future. Could we catch Throwable, complete the future exceptionally, and rethrow Errors?
There was a problem hiding this comment.
Fixed — refresh now catches Throwable, completes the shared future so inFlight is cleared, and rethrows Errors unchanged.
| .build(); | ||
| this.refreshAfterMillis = resolveRefreshAfterMillis(builder.refreshAfter); | ||
| this.onTokenChanged = builder.onTokenChanged; | ||
| this.callbackExecutor = builder.callbackExecutor == null |
There was a problem hiding this comment.
One thing here, the callback runs on commonPool(), which the whole application shares (as few as one thread on a small host), and callbackExecutor isn't public, so a customer with a slow onTokenChanged (e.g. re-authenticating many connections) can stall unrelated work with no way to opt out.
We'd like all three languages to behave the same here: run the callback on the manager's own refresh thread, right after the token is installed and the lock is released, still off the caller's path, but on a thread we own. Suggestion: drop the executor and call onTokenChanged.accept(token) directly at the end of installAndComplete (outside synchronized), keep the try/catch, and note in the Javadoc that the callback should return quickly since it delays only the next refresh. Open to discuss this
There was a problem hiding this comment.
Addressed. onTokenChanged now runs on the manager's own single refresh thread after the token is installed, the refresh is completed, and the lock is released.
Summary
ElastiCacheIamAuthTokenManagerfor lazy token caching and background refresh.Errors so later token requests can recover.TokenRefreshExceptionfor operational failures.Verification