The streaming thread in StreamExecution uses the following ways to check if it should exit:
- Catch an InterruptException.
- `StreamExecution.state` is TERMINATED.
when starting and stopping a query quickly, the above two checks may both fail.
- Hit HADOOP-14084 and swallow InterruptException
- StreamExecution.stop is called before `state` becomes `ACTIVE`. Then runBatches changes the state from `TERMINATED` to `ACTIVE`.
If the above cases both happen, the query will hang forever.