                                     if p._socket_id == socket.id
                                         p.clear_state()
                                         delete p._socket_id
-                                if @_socket_cache[opts.host]?.id == socket.id
-                                    delete @_socket_cache[opts.host]
+                                if @_socket_cache[host]?.id == socket.id
+                                    delete @_socket_cache[host]
                                 socket.removeAllListeners()
                             socket.on 'mesg', (type, mesg) =>
                                 if type == 'json'
                                     if mesg.event == 'project_state_update'
                                         winston.debug("state_update #{misc.to_safe_str(mesg)}")
                                         p = @_project_cache[mesg.project_id]
-                                        if p? and p.host == opts.host  # ignore updates from wrong host
+                                        if p? and p.host == host  # ignore updates from wrong host
                                             p._state      = mesg.state
                                             p._state_time = new Date()
                                             p._state_set_by = socket.id

                                            if STATES[mesg.state].stable
                                                p.emit('stable', mesg.state)
                                    else
                                        winston.debug("mesg (hub <- #{opts.host}): #{misc.to_safe_str(mesg)}")
                            cb()
        ], (err) =>
            opts.cb(err, @_socket_cache[opts.host])
        )

    ###

            opts.cb(undefined, socket)
            return

        # IMPORTANT: in case socket gets called many times at once with the same host as input,
        # we must only get a socket once, then return it to all the callers.
        if not @_socket_cbs?
            @_socket_cbs = {}
        if not @_socket_cbs[opts.host]?
            @_socket_cbs[opts.host] = [opts.cb]
            @_get_socket opts.host, (err, socket) =>
                if socket?
                    # Cache the socket we just got
                    @_socket_cache[opts.host] = socket
                # Get list of callbacks to notify
                v = @_socket_cbs[opts.host]
                delete @_socket_cbs[opts.host]  # don't notify again
                # Notify callbacks
                for cb in v
                    cb(err, socket)
        else
            @_socket_cbs[opts.host].push(opts.cb)

    # the following is used internally by @socket to actually get a socket, but with no
    # checking or caching.
    _get_socket: (host, cb) =>
        dbg = @dbg("socket(#{host})")
        if @_dev
            dbg("development mode 'socket'")
            require('./compute-server').fake_dev_socket (err, socket) =>
                if err
                    cb(err)
                else
                    @_socket_cache[host] = socket
                    socket.on 'mesg', (type, mesg) =>
                        if type == 'json'
                            if mesg.event == 'project_state_update'
