RFR: 8304818: Prune HttpURLConnection cache when corresponding Authenticator is garbage collected [v8]

Daniel Fuchs dfuchs at openjdk.org
Wed Apr 12 11:09:00 UTC 2023


On Wed, 12 Apr 2023 09:48:13 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Michael McMahon has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   update to remove dependency on AuthCacheImpl in j.n.Authenticator
>
> src/java.base/share/classes/sun/net/www/protocol/http/AuthCacheImpl.java line 122:
> 
>> 120:         if (c == null) {
>> 121:             c = new AuthCacheImpl();
>> 122:             caches.put(auth, c);
> 
> It appears that there's a potential for a race here, which could end up (creating and) returning a different `AuthCacheImpl` for the same `auth` instance.
> Even though the `caches` is a `synchronizedMap`, we are using it here for two separate operations (`get()` followed by `put()`) which makes this non-atomic. Perhaps add a `synchronized` block `sychronized` on `caches`, if `c` is null?

Or maybe use computeIfAbsent ?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163974073


More information about the net-dev mailing list