Fix deadlock while closing AsyncWriteEngine. Issue 137, credit Jan Sileny