[ 
https://issues.apache.org/jira/browse/BEAM-9474?focusedWorklogId=400417&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-400417
 ]

ASF GitHub Bot logged work on BEAM-9474:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Mar/20 22:34
            Start Date: 09/Mar/20 22:34
    Worklog Time Spent: 10m 
      Work Description: mxm commented on pull request #11084: [BEAM-9474] 
Improve robustness of BundleFactory and ProcessEnvironment
URL: https://github.com/apache/beam/pull/11084#discussion_r389998500
 
 

 ##########
 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:
   Not strictly, but the iterator could throw. I'm trying to be extra defensive 
here.
 
----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 400417)
    Time Spent: 1.5h  (was: 1h 20m)

> Environment cleanup is not robust enough and may leak resources
> ---------------------------------------------------------------
>
>                 Key: BEAM-9474
>                 URL: https://issues.apache.org/jira/browse/BEAM-9474
>             Project: Beam
>          Issue Type: Bug
>          Components: java-fn-execution
>            Reporter: Maximilian Michels
>            Assignee: Maximilian Michels
>            Priority: Major
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> The cleanup code in {{DefaultJobBundleFactory}} and its {{RemoteEnvironment}} 
> s may leak resources. This is especially a concern when the execution engines 
> reuses the same JVM or underlying machines for multiple runs of a pipeline.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to