Github user vrozov commented on a diff in the pull request: https://github.com/apache/drill/pull/1023#discussion_r148888668 --- 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(); --- End diff -- Usually, lock is called outside of try to avoid calling unlock in finally if lock was not successful.
---