You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/02/25 17:31:30 UTC

[GitHub] [accumulo] keith-turner commented on a change in pull request #2524: Beginning to address unchecked Futures

keith-turner commented on a change in pull request #2524:
URL: https://github.com/apache/accumulo/pull/2524#discussion_r814960271



##########
File path: core/src/main/java/org/apache/accumulo/core/util/threads/ThreadPools.java
##########
@@ -47,6 +51,70 @@
   // the number of seconds before we allow a thread to terminate with non-use.
   public static final long DEFAULT_TIMEOUT_MILLISECS = 180000L;
 
+  private static final ThreadPoolExecutor SCHEDULED_FUTURE_CHECKER_POOL =
+      createFixedThreadPool(1, "Scheduled Future Checker", false);
+
+  private static final ConcurrentLinkedQueue<ScheduledFuture<?>> CRITICAL_RUNNING_TASKS =
+      new ConcurrentLinkedQueue<>();
+
+  private static Runnable CRITICAL_TASK_CHECKER = new Runnable() {
+    @Override
+    public void run() {
+      while (true) {
+        Iterator<ScheduledFuture<?>> futures = CRITICAL_RUNNING_TASKS.iterator();
+        while (futures.hasNext()) {
+          ScheduledFuture<?> criticalTask = futures.next();
+          // Calling get() on a ScheduledFuture will block unless that scheduled task has
+          // completed. We call isDone() here instead. If the scheduled task is done then
+          // either it was a one-shot task, cancelled or an exception was thrown.
+          if (criticalTask.isDone()) {
+            // Now call get() to see if we get an exception.
+            try {
+              criticalTask.get();
+              // If we get here, then a scheduled task exited but did not throw an error
+              // or get canceled. This was likely a one-shot scheduled task.
+              if (!CRITICAL_RUNNING_TASKS.remove(criticalTask)) {
+                LOG.warn("Unable to remove task from list of watched critical tasks");
+              }
+            } catch (ExecutionException ee) {
+              // An exception was thrown in the critical task. Throw the error here, which
+              // will then be caught by the AccumuloUncaughtExceptionHandler which will
+              // log the error and terminate the VM.
+              throw new RuntimeException("Critical scheduled task failed.", ee.getCause());

Review comment:
       Calling ee.getCause() drops the stack trace associated with the ExecutionException which may contain important info for debugging problems.   The uncaughtexceptionhandler only halts the VM when its an error.  Since this is not an error then them VM will not be halted and this thread that checks future will be dead. 
   
   ```suggestion
                 throw new RuntimeException("Critical scheduled task failed.", ee);
   ```




-- 
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: notifications-unsubscribe@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org