Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while run concurrently with bluebird #7104

Closed
phuongnq opened this issue Jan 29, 2019 · 2 comments
Closed

Error while run concurrently with bluebird #7104

phuongnq opened this issue Jan 29, 2019 · 2 comments

Comments

@phuongnq
Copy link

While running 2 instances of browser with Bluebird (http://bluebirdjs.com/docs/getting-started.html). I got following error:

{ Error: no known mark: lh:gather:loadBlank
    at Object.exports.stop (/Users/dummy.user/node_modules/marky/lib/marky.cjs.js:76:13)
    at Function.timeEnd (/Users/dummy.user/node_modules/lighthouse-logger/index.js:128:11)
    at Function.loadBlank (/Users/dummy.user/node_modules/lighthouse/lighthouse-core/gather/gather-runner.js:78:9)
    at processTicksAndRejections (internal/process/next_tick.js:81:5) friendlyMessage: undefined }
(node:11724) UnhandledPromiseRejectionWarning: Error: no known mark: lh:gather:loadBlank
    at Object.exports.stop (/Users/dummy.user/node_modules/marky/lib/marky.cjs.js:76:13)
    at Function.timeEnd (/Users/dummy.user/node_modules/lighthouse-logger/index.js:128:11)
    at Function.loadBlank (/Users/dummy.user/node_modules/lighthouse/lighthouse-core/gather/gather-runner.js:78:9)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
(node:11724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The issue is about some log function from gather-runner.js. If I disable log functions const log = require('lighthouse-logger');, it works as expected.
Here is my sample code:

const puppeteer = require('puppeteer');
const lighthouse = require('lighthouse');
const {URL} = require('url');
const Promise = require('bluebird');

(async() => {

let browser1, browser2;
const task1 = () => (new Promise(async (resolve, reject) => {
    try {
        const url = 'https://github.com';
        // Use Puppeteer to launch headful Chrome and don't use its default 800x600 viewport.
        browser1 = await puppeteer.launch({
            headless: false,
            defaultViewport: null,
        });

        // Wait for Lighthouse to open url, then customize network conditions.
        // Note: this will re-establish these conditions when LH reloads the page. Think that's ok....
        browser1.on('targetchanged', async target => {
            const page = await target.page();

            function addStyleContent(content) {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.appendChild(document.createTextNode(content));
            document.head.appendChild(style);
            }

            const css = '* {color: red}';

            if (page && page.url() === url) {
            // Note: can't use page.addStyleTag due to github.com/GoogleChrome/puppeteer/issues/1955.
            // Do it ourselves.
            const client = await page.target().createCDPSession();
            await client.send('Runtime.evaluate', {
                expression: `(${addStyleContent.toString()})('${css}')`
            });
            }
        });

        const {lhr} = await lighthouse(url, {
            port: (new URL(browser1.wsEndpoint())).port,
            output: 'json',
            logLevel: 'info',
        });
        console.log(`Lighthouse scores: ${Object.values(lhr.categories).map(c => c.score).join(', ')}`);
        await browser1.close();
        return resolve(true);
    } catch (ex) {
        console.log(ex);
        reject(ex);
    }
}));

const task2 = () => (new Promise(async (resolve, reject) => {
    try {
        const url = 'https://github.com';
        // Use Puppeteer to launch headful Chrome and don't use its default 800x600 viewport.
        browser2 = await puppeteer.launch({
            headless: false,
            defaultViewport: null,
        });

        // Wait for Lighthouse to open url, then customize network conditions.
        // Note: this will re-establish these conditions when LH reloads the page. Think that's ok....
        browser2.on('targetchanged', async target => {
            const page = await target.page();

            function addStyleContent(content) {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.appendChild(document.createTextNode(content));
            document.head.appendChild(style);
            }

            const css = '* {color: red}';

            if (page && page.url() === url) {
            // Note: can't use page.addStyleTag due to github.com/GoogleChrome/puppeteer/issues/1955.
            // Do it ourselves.
            const client = await page.target().createCDPSession();
            await client.send('Runtime.evaluate', {
                expression: `(${addStyleContent.toString()})('${css}')`
            });
            }
        });

        const {lhr} = await lighthouse(url, {
            port: (new URL(browser2.wsEndpoint())).port,
            output: 'json',
            logLevel: 'info',
        });
        console.log(`Lighthouse scores: ${Object.values(lhr.categories).map(c => c.score).join(', ')}`);
        await browser2.close();
        return resolve(true);
    } catch (ex) {
        console.log(ex);
        reject(ex);
    }
}));

const tasks = [task1, task2];

console.log(tasks);

const res = await Promise.map(
    tasks,
    job => job(),
    { concurrency: 2 }
);
console.log(res);
console.log(browser1 === browser2);
})();
@patrickhulce
Copy link
Collaborator

Thanks for filing @phuongnq! Unfortunately, running LH concurrently in the same node process isn't really supported (you've run into one of the gotchas here, but there are a few more). You'll have to run them in separate child process to run LH concurrently.

It's also worth noting that running LH concurrently on the same machine can skew performance results due to resource contention, so it's not the recommended approach on typical machines (if you have plenty of cores, i.e. 12+, and more network bandwidth than you know what to do with, then it's probably fine).

@phuongnq
Copy link
Author

Thanks for the response @patrickhulce!

If it is not fully support we can close this ticket. Running on different processes should be a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants