             if data.toString() == 'y'
                 if timer?
                     clearTimeout(timer)
-                    cb(false, socket)
+                    cb?(false, socket)
+                    cb = undefined
             else
                 socket.destroy()
                 if timer?
                     clearTimeout(timer)
-                    cb("Permission denied (invalid secret token) when connecting to the local hub.")
+                    cb?("Permission denied (invalid secret token) when connecting to the local hub.")
+                    cb = undefined
         socket.on 'data', listener
         winston.debug("misc_node: connected, now sending secret token")
         socket.write(token)

    timed_out = () ->
        m = "misc_node: timed out trying to connect to locked socket on port #{port}"
        winston.debug(m)
        cb(m)
        socket.end()
        timer = undefined


    socket.on "error", (err) =>
        if timer?
            clearTimeout(timer)
        cb?(err)
        cb = undefined



# Compute a uuid v4 from the Sha-1 hash of data.
