Make sure socket is closed after failed connection attempt.
Do not use socket.sendall() on non-blocking socket.
Make sure heartbeat is not executed when no longer active.