fix bug where socket was destroyed on connection failure