From 4f0708ce15cc62662e3746262e8092913c24906e Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 25 Mar 2020 17:35:43 +0000 Subject: Add timeout on Javascript latch awaits 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 --- .../apex/plugins/executor/javascript/JavascriptExecutor.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'plugins/plugins-executor/plugins-executor-javascript') diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java index 2394b83d3..f7bafdd74 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java @@ -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(); -- cgit 1.2.3-korg