anmolanmol1234 commented on code in PR #7817: URL: https://github.com/apache/hadoop/pull/7817#discussion_r2260188357
########## hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/KeepAliveCache.java: ########## @@ -259,48 +151,39 @@ public synchronized HttpClientConnection get() * will make space for the new connection. If the cache is closed or of zero size, * the connection is closed and not added to the cache. * - * @param httpClientConnection HttpClientConnection to be cached + * @param conn HttpClientConnection to be cached * @return true if the HttpClientConnection is added in active cache, false otherwise. */ - public synchronized boolean put(HttpClientConnection httpClientConnection) { - if (isClosed.get() || maxConn == 0) { - closeHttpClientConnection(httpClientConnection); + public boolean add(HttpClientConnection conn) { + if (conn == null) { + LOG.warn("Attempt to add null HttpClientConnection to the cache for account: {}", + accountNamePath); return false; } - if (size() == maxConn) { - closeHttpClientConnection(get(0).httpClientConnection); - subList(0, 1).clear(); + if (isClosed.get() || maxCacheConnections <= 0 + || !conn.isOpen() || conn.isStale()) { + closeHttpClientConnection(conn); + return false; + } + while (size() >= maxCacheConnections) { Review Comment: Since this method is not synchronized two threads can enter this loop simultaneously, both see size = maxCacheConnections, both remove one, and both add a new one — leading to the cache momentarily holding more than maxCacheConnections. So, the eviction logic should be synchronized -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org