fix race where connect and disconnect callbacks called in a row