Drill may never terminate in the event of a Heap OOM. When this happens we see stack traces like the following:
Here CatastrophicFailure.exit is being called when we encounter a Heap OOM. Then we call System.exit to terminate the java process. The only issue is that System.exit run's Drill's normal shutdown hook and tries to do a graceful shutdown. In the case of a Heap OOM we cannot do this reliable because there physically isn't enough memory to proceed executing our code. The JVM likely gets stuck a various places waiting on garbage collection and object allocations on the heap and the Drillbit stops making progress.
Solution To Hanging Shutdown
There are two kinds of OutOfMemory exceptions in Drill. Direct Memory OOMs and Heap OOMs. Typically Direct Memory OOMs are recoverable because Drill uses Direct Memory to store data only, so we can fail a query and lose data and recover. Heap OOMs are unrecoverable because we actually need the Heap to execute our code, and if we can't use the heap then we basically can't run our code reliably.
When Drill experiences a catastrophic failure we should not call System.exit because then we will try to shutdown gracefully. In the event of a catastrophic failure like a Heap OOM we cannot recover so we should forcefully terminate the jvm with Runtime.getRuntime().halt .
This will make Drill shutdown promptly in the event of a Heap OOM.