Fix draining, EOS and flushing logic to not deadlock