@@ -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