vahmed-hamdy commented on code in PR #25569:
URL: https://github.com/apache/flink/pull/25569#discussion_r1856326806


##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManager.java:
##########
@@ -269,19 +270,30 @@ public synchronized void close(long timeoutMs) throws 
Exception {
         // fetcher threads blocking on putting batches into the element queue.
         executors.submit(
                 () -> {
-                    while (fetchersToShutDown.get() > 0
-                            && System.currentTimeMillis() - startTime < 
timeoutMs) {
-                        elementsQueue
-                                .getAvailabilityFuture()
-                                .thenRun(() -> elementsQueue.poll().recycle());
+                    long timeElapsed = System.currentTimeMillis() - startTime;
+                    while (fetchersToShutDown.get() > 0 && timeElapsed < 
timeoutMs) {
+                        try {
+                            elementsQueue
+                                    .getAvailabilityFuture()
+                                    .thenRun(() -> 
elementsQueue.poll().recycle())
+                                    .get(timeoutMs - timeElapsed, 
TimeUnit.MILLISECONDS);
+                        } catch (Exception e) {
+                            LOG.warn(
+                                    "Received exception when waiting for the 
fetchers to "
+                                            + "shutdown.",
+                                    e);
+                            break;
+                        }
+                        timeElapsed = System.currentTimeMillis() - startTime;
                     }
                 });
         executors.shutdown();
-        if (!executors.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS)) {
+        long timeElapsed = System.currentTimeMillis() - startTime;
+        if (!executors.awaitTermination(timeoutMs - timeElapsed, 
TimeUnit.NANOSECONDS)) {
             LOG.warn(
-                    "Failed to close the split fetchers in {} ms. There are 
still {} split fetchers running",
+                    "Failed to close the source reader in {} ms. There are 
still {} split fetchers running",

Review Comment:
   nit: why are we changing the warn message?



##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManager.java:
##########
@@ -269,19 +270,30 @@ public synchronized void close(long timeoutMs) throws 
Exception {
         // fetcher threads blocking on putting batches into the element queue.
         executors.submit(
                 () -> {
-                    while (fetchersToShutDown.get() > 0
-                            && System.currentTimeMillis() - startTime < 
timeoutMs) {
-                        elementsQueue
-                                .getAvailabilityFuture()
-                                .thenRun(() -> elementsQueue.poll().recycle());
+                    long timeElapsed = System.currentTimeMillis() - startTime;
+                    while (fetchersToShutDown.get() > 0 && timeElapsed < 
timeoutMs) {
+                        try {
+                            elementsQueue
+                                    .getAvailabilityFuture()
+                                    .thenRun(() -> 
elementsQueue.poll().recycle())
+                                    .get(timeoutMs - timeElapsed, 
TimeUnit.MILLISECONDS);
+                        } catch (Exception e) {

Review Comment:
   Should we catch more specific? maybe we need to break on 
`InterruptedException` but we just continue trying to wait on the others if it 
is an `ExecutionException`?



##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -100,6 +102,50 @@ void testCloseCleansUpPreviouslyClosedFetcher() throws 
Exception {
         fetcherManager.close(Long.MAX_VALUE);
     }
 
+    /**

Review Comment:
   This comment could be removed



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