           throw error
 
   logIn: ->
+    # Makes sure there is not session id left.
+    delete @sessionId
+
     @sessionId = @call 'session.login_with_password', @username, @password
 
 #=====================================================================

          # Node.js seems to reuse the broken socket, so we add a small
          # delay.
          #
          # TODO Magic number!!!
          #
          # I would like to be able to use a shorter delay but for
          # some reason, when we connect to XAPI at a given moment,
          # the connection hangs.
          $sleep 500
          helper()

        # XAPI is sometimes reinitialized and sessions are lost.
        # We try log in again if necessary.
        when 'SESSION_INVALID'
          @logIn()
          helper()


    if !force and (hostname is @xmlrpc?.options.host)
      return

    @xmlrpc = $xmlrpc.createSecureClient {
      host: hostname
      port: port ? 443
