Fix possible deadlock in reconnecting