fix use-after-free when disconnected