Github user ilooner commented on a diff in the pull request: https://github.com/apache/drill/pull/1023#discussion_r148896551 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/work/WorkManager.java --- @@ -158,38 +165,51 @@ public DrillbitContext getContext() { return dContext; } - private ExtendedLatch exitLatch = null; // used to wait to exit when things are still running - /** * Waits until it is safe to exit. Blocks until all currently running fragments have completed. - * - * <p>This is intended to be used by {@link org.apache.drill.exec.server.Drillbit#close()}.</p> + * This is intended to be used by {@link org.apache.drill.exec.server.Drillbit#close()}. */ public void waitToExit() { - synchronized(this) { - if (queries.isEmpty() && runningFragments.isEmpty()) { - return; + final long startTime = System.currentTimeMillis(); + + try { + exitLock.lock(); + long diff; + while ((diff = (System.currentTimeMillis() - startTime)) < EXIT_TIMEOUT) { + if (queries.isEmpty() && runningFragments.isEmpty()) { + break; + } + + try { + final boolean success = exitCondition.await(EXIT_TIMEOUT - diff, TimeUnit.MILLISECONDS); + + if (!success) { + logger.warn("Timed out after %d millis while waiting to exit.", EXIT_TIMEOUT); + exitLock.lock(); + } + } catch (InterruptedException e) { + logger.warn("Interrupted while waiting to exit"); + exitLock.lock(); + } } - exitLatch = new ExtendedLatch(); - } + if (!(queries.isEmpty() && runningFragments.isEmpty())) { + logger.warn("Timed out after %d millis. Shutting down before all fragments and foremen " + + "have completed.", EXIT_TIMEOUT); --- End diff -- This should actually just break from the loop instead of print a message, since EXIT_TIMEOUT millis have elapsed in this case, and the Timed out message is already printed below. I've updated the PR with this change.
---