socket closing and handling handshake timeout