Only open a new socket for HA if the current socket is dead #859 and #857