prevent race conditions in logout