Fixed connection failure. Port of this code was missed while cherry-picking from erkmos/master.