fix closing and deregistering connection when connect fails (#128)