Skip to content

Commit 4e2cdcc

Browse files
nastradanielcweeks
authored andcommitted
AWS: Make AuthSession cache static (#7289)
Signer instances can be fairly short-lived, meaning that the `AuthSession` cache doesn't get a chance to remove an `AuthSession` from the cache and thus call `AuthSession#stopRefreshing()`.
1 parent bcb4f35 commit 4e2cdcc

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3V4RestSignerClient.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public abstract class S3V4RestSignerClient
8080
@SuppressWarnings("immutables:incompat")
8181
private static volatile RESTClient httpClient;
8282

83+
@SuppressWarnings("immutables:incompat")
84+
private static volatile Cache<String, AuthSession> authSessionCache;
85+
8386
public abstract Map<String, String> properties();
8487

8588
@Value.Default
@@ -135,24 +138,33 @@ ScheduledExecutorService tokenRefreshExecutor() {
135138
return tokenRefreshExecutor;
136139
}
137140

138-
@Value.Lazy
139-
Cache<String, AuthSession> authSessionCache() {
140-
long expirationIntervalMs =
141-
PropertyUtil.propertyAsLong(
142-
properties(),
143-
CatalogProperties.AUTH_SESSION_TIMEOUT_MS,
144-
CatalogProperties.AUTH_SESSION_TIMEOUT_MS_DEFAULT);
145-
146-
return Caffeine.newBuilder()
147-
.expireAfterAccess(Duration.ofMillis(expirationIntervalMs))
148-
.removalListener(
149-
(RemovalListener<String, AuthSession>)
150-
(id, auth, cause) -> {
151-
if (null != auth) {
152-
auth.stopRefreshing();
153-
}
154-
})
155-
.build();
141+
private Cache<String, AuthSession> authSessionCache() {
142+
if (null == authSessionCache) {
143+
synchronized (S3V4RestSignerClient.class) {
144+
if (null == authSessionCache) {
145+
long expirationIntervalMs =
146+
PropertyUtil.propertyAsLong(
147+
properties(),
148+
CatalogProperties.AUTH_SESSION_TIMEOUT_MS,
149+
CatalogProperties.AUTH_SESSION_TIMEOUT_MS_DEFAULT);
150+
151+
authSessionCache =
152+
Caffeine.newBuilder()
153+
.expireAfterAccess(Duration.ofMillis(expirationIntervalMs))
154+
.removalListener(
155+
(RemovalListener<String, AuthSession>)
156+
(id, auth, cause) -> {
157+
if (null != auth) {
158+
LOG.trace("Stopping refresh for AuthSession");
159+
auth.stopRefreshing();
160+
}
161+
})
162+
.build();
163+
}
164+
}
165+
}
166+
167+
return authSessionCache;
156168
}
157169

158170
private RESTClient httpClient() {

0 commit comments

Comments
 (0)