                                     p.emit(p._state, p)
                                     if STATES[mesg.state].stable
                                         p.emit('stable', mesg.state)
-                    opts.cb(undefined, socket)
+                    cb(undefined, socket)
             return
 
         info = undefined
+        socket = undefined
         async.series([
             (cb) =>
                 dbg("getting port and secret...")
                 @database.get_compute_server
-                    host : opts.host
+                    host : host
                     cb   : (err, x) =>
                         info = x; cb(err)
             (cb) =>
-                dbg("connecting to #{opts.host}:#{info.port}...")
+                dbg("connecting to #{host}:#{info.port}...")
                 misc_node.connect_to_locked_socket
-                    host    : opts.host
+                    host    : host
                     port    : info.port
                     token   : info.secret
                     timeout : 15
-                    cb      : (err, socket) =>
+                    cb      : (err, _socket) =>
                         if err
                             dbg("failed to connect: #{err}")
                             cb(err)
                         else
-                            @_socket_cache[opts.host] = socket
+                            socket = _socket
                             misc_node.enable_mesg(socket)
                             socket.id = uuid.v4()
                             dbg("successfully connected -- socket #{socket.id}")

                                    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]
                                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
                                            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 <- #{host}): #{misc.to_safe_str(mesg)}")
                            cb()
        ], (err) =>
            cb(err, socket)
        )

    ###
