anmolanmol1234 commented on code in PR #7817:
URL: https://github.com/apache/hadoop/pull/7817#discussion_r2313786906


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsConnectionManager.java:
##########
@@ -290,35 +298,45 @@ private void logDebug(String message, Object... args) {
    * @param route the HTTP route for which connections are created
    * @param numberOfConnections the number of connections to create
    */
-  private void cacheExtraConnection(final HttpRoute route, final int 
numberOfConnections) {
-    if (!isCaching.getAndSet(true)) {
-      long start = System.currentTimeMillis();
-      // Only one thread allowed at a time
-      ExecutorService executorService = 
Executors.newFixedThreadPool(Math.min(numberOfConnections, 5));
+  private void cacheExtraConnection(final HttpRoute route,
+      final int numberOfConnections) {
+    if (!isCacheRefreshInProgress.getAndSet(true)) {
+      long start = System.nanoTime();
+      CountDownLatch latch = new CountDownLatch(numberOfConnections);
 
       for (int i = 0; i < numberOfConnections; i++) {
-        executorService.submit(() -> {
+        kac.getFixedThreadPool().submit(() -> {
+          HttpClientConnection conn = null;
           try {
-            HttpClientConnection conn = httpConnectionFactory.create(route, 
null);
-            connect(conn, route, connectionTimeout, new 
AbfsManagedHttpClientContext());
+            conn = httpConnectionFactory.create(route, null);
+            connect(conn, route, abfsConfiguration.getHttpConnectionTimeout(),
+                new AbfsManagedHttpClientContext());
             addConnectionToCache(conn);
           } catch (Exception e) {
-           logDebug("Error creating connection: {}", e.getMessage());
+            logDebug("Error creating connection: {}", e.getMessage());
+            if (conn != null) {
+              try {
+                conn.close();
+              } catch (IOException ioException) {
+                logDebug("Error closing connection: {}",
+                    ioException.getMessage());
+              }
+            }
+          } finally {
+            latch.countDown();
           }
         });
       }
 
-      executorService.shutdown();
       try {
-        if (!executorService.awaitTermination(1, TimeUnit.SECONDS)) {
-          executorService.shutdownNow();
-        }
+        // Wait for all connections to be created before releasing the lock
+        latch.await();

Review Comment:
   Add latch timeout else it might keep waiting forever



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

Reply via email to