You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by GitBox <gi...@apache.org> on 2020/03/09 22:08:10 UTC

[GitHub] [beam] tweise commented on a change in pull request #11084: [BEAM-9474] Improve robustness of BundleFactory and ProcessEnvironment

tweise commented on a change in pull request #11084: [BEAM-9474] Improve robustness of BundleFactory and ProcessEnvironment
URL: https://github.com/apache/beam/pull/11084#discussion_r389982978
 
 

 ##########
 File path: runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/control/DefaultJobBundleFactory.java
 ##########
 @@ -252,14 +263,47 @@ public StageBundleFactory forStage(ExecutableStage executableStage) {
   }
 
   @Override
-  public void close() throws Exception {
-    // Clear the cache. This closes all active environments.
-    // note this may cause open calls to be cancelled by the peer
-    for (LoadingCache<Environment, WrappedSdkHarnessClient> environmentCache : environmentCaches) {
-      environmentCache.invalidateAll();
-      environmentCache.cleanUp();
+  public synchronized void close() throws Exception {
+    if (closed) {
+      return;
+    }
+    Exception exception = null;
+    try {
+      for (LoadingCache<Environment, WrappedSdkHarnessClient> environmentCache :
+          environmentCaches) {
+        try {
+          // Clear the cache. This closes all active environments.
+          // note this may cause open calls to be cancelled by the peer
+          environmentCache.invalidateAll();
+          environmentCache.cleanUp();
+        } catch (Exception e) {
+          if (exception != null) {
+            exception.addSuppressed(e);
+          } else {
+            exception = e;
+          }
+        }
+      }
+      try {
+        executor.shutdown();
+      } catch (Exception e) {
+        if (exception != null) {
+          exception.addSuppressed(e);
+        } else {
+          exception = e;
+        }
+      }
+    } catch (Exception e) {
 
 Review comment:
   The outer try/catch isn't necessary since you already have it nested.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services