FrankYang0529 commented on code in PR #22759:
URL: https://github.com/apache/kafka/pull/22759#discussion_r4656409773


##########
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/VerificationKeyResolverFactory.java:
##########
@@ -180,8 +189,12 @@ public void configure(Map<String, ?> configs, String 
saslMechanism, List<AppConf
 
         @Override
         public void close() throws IOException {
-            if (count.decrementAndGet() == 0)
+            if (count.decrementAndGet() == 0) {
+                // Drop the cache entry so that a later get() with the same 
configuration builds a new
+                // resolver rather than resurrecting this closed one.
+                remove(cacheKey);

Review Comment:
   Thanks, good catch. The root cause is that `get()` returned the resolver 
without taking a reference. The reference was only taken later in 
`configure()`. Moving the count updates under the lock would not be enough on 
its own, because another caller could still close the resolver between `get()` 
and `configure()`.
   
   Now `get()` acquires the reference under the factory lock, and `close()` 
releases it under the same lock. When the last reference is released, the cache 
entry is removed (only if it still maps to this resolver) before the delegate 
is closed. `configure()` no longer touches the count.



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

Reply via email to