[#1310] Fix deadlock which can happen if limit of MemoryAwareThreadPoolExecutor was exceed and a close is triggered by a write

* Close must be handled from outside the write lock to fix a possible deadlock
  which can happen when MemoryAwareThreadPoolExecutor is used and the limit is exceed
  and a close is triggered while the lock is hold. This is because the close(..)
  may try to submit a task to handle it via the ExecutorHandler which then deadlocks.