Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the race between close and destroy in the Driver
There is a race condition where a driver thread may not destroy the operators even though it's closed. This is not desirable as there are parts of the code that rely on the operators to be destroyed by the driver, e.g., memory tracking related code. The race occurs when a driver thread T1 is in the tryWithLock method and holds the exclusiveLock, and it has already called the destroyIfNecessary() method. At this point T1 hasn't destroyed the operators yet as the driver hasn't been closed. Now if the task owning those splits gets aborted (say due to a LIMIT query), another thread T2 will call driver.close(), and in close() it will try to acquire the lock to destroy the operators, but T1 still holds that lock. Then, T1 releases the lock and checks the condition `while (pendingTaskSourceUpdates.get() != null && state.get() == State.ALIVE && exclusiveLock.tryLock())`, and this condition is false as the state is NEED_DESTRUCTION (as the driver is closed by T2). At this point T1 just exits without destroying the operators.
- Loading branch information