Fix deadlock when trying to close an account

Should fix #3044.