Add timeout on Javascript latch awaits 99/104399/1
authorliamfallon <liam.fallon@est.tech>
Wed, 25 Mar 2020 17:35:43 +0000 (17:35 +0000)
committerliamfallon <liam.fallon@est.tech>
Wed, 25 Mar 2020 17:38:25 +0000 (17:38 +0000)
It is possible that the initiation and especially shutdown happens so
fast that the execution thread counts down the latch before the caller
calls await(), in which case the Javascript Rhino thread will hang. This
review adds a timeout on the await calls.

Issue-ID: POLICY-2106
Change-Id: Icfc6d4b478cca62522461c25d61ce9ee7328684a
Signed-off-by: liamfallon <liam.fallon@est.tech>
plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java

index 2394b83..f7bafdd 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.policy.apex.plugins.executor.javascript;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.commons.lang3.StringUtils;
@@ -102,7 +103,9 @@ public class JavascriptExecutor implements Runnable {
         }
 
         try {
-            intializationLatch.await();
+            if (!intializationLatch.await(60, TimeUnit.SECONDS)) {
+                LOGGER.warn("JavascriptExecutor {}, initiation timed out", subjectKey.getId());
+            }
         } catch (InterruptedException e) {
             LOGGER.debug("JavascriptExecutor {} interrupted on execution thread startup", subjectKey.getId(), e);
             Thread.currentThread().interrupt();
@@ -158,7 +161,9 @@ public class JavascriptExecutor implements Runnable {
         executorThread.interrupt();
 
         try {
-            shutdownLatch.await();
+            if (!shutdownLatch.await(60, TimeUnit.SECONDS)) {
+                LOGGER.warn("JavascriptExecutor {}, shutdown timed out", subjectKey.getId());
+            }
         } catch (InterruptedException e) {
             LOGGER.debug("JavascriptExecutor {} interrupted on execution clkeanup wait", subjectKey.getId(), e);
             Thread.currentThread().interrupt();