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

[BUG] Attach multiple instance of playwright to browser server #3405

Closed
phileba opened this issue Aug 12, 2020 · 6 comments
Closed

[BUG] Attach multiple instance of playwright to browser server #3405

phileba opened this issue Aug 12, 2020 · 6 comments
Assignees

Comments

@phileba
Copy link

phileba commented Aug 12, 2020

The story is I want to do load test with the playwright, I've tried to simulate multiple users use the playwright to run the automation.

  • The first thing I create the browser server by
const broserServer = playwright.chromium.launchServer({ headless: false })
const wsEndpoint = browserServer.wsEndpoint()
  • Then I create multiple children thread, postMessage to each thread and send the wsEndpoint for the child thread connect to browser server:
...
async function runMethod(wsEndpoint: string) {
	const browser = await playwright.chromium.connect({ wsEndpoint })
	const page = await browser.newPage()
	await page.goto('https://google.com.vn')
	break
}
  • So the result is if I try to run with 1 or 2 threads, it works fine but If if 4 or more threads, the instance can not connect to the browser server (status connecting). Do you have any idea?
@dgozman
Copy link
Contributor

dgozman commented Aug 13, 2020

Sounds like a bug, let me look into that.

@dgozman dgozman changed the title Attach multiple instance of playwright to browser server [BUG] Attach multiple instance of playwright to browser server Aug 13, 2020
@dgozman dgozman self-assigned this Aug 13, 2020
@dgozman dgozman added the v1.4 label Aug 13, 2020
@dgozman
Copy link
Contributor

dgozman commented Aug 14, 2020

I tried to repro with playwright v1.3.0 on my mac, but everything works for me. My setup is probably different, so repro script would be very much appreciated!

const playwright = require('playwright');

(async () => {
  const browserServer = await playwright.chromium.launchServer({ headless: false });
  const promises = Array(20).fill(0).map(async () => {
    const browser = await playwright.chromium.connect({ wsEndpoint: browserServer.wsEndpoint() });
    const page = await browser.newPage();
    await page.goto('https://google.com.vn');
    console.log('connected one more');
    return browser;
  });
  const browsers = await Promise.all(promises);
  const closedPromises = browsers.map(browser => new Promise(f => {
    browser.once('disconnected', () => {
      console.log('closed one more');
      f();
    });
  }));
  await Promise.all([
    browserServer.close(),
    ...closedPromises
  ]);
})();

@phileba
Copy link
Author

phileba commented Aug 17, 2020

Here is the script to repro, run in headless mode:

#parent class:

const browserServer = await playwright.chromium.launchServer();
for (let i = 0; i < 20; i++) {
	const worker = new WorkerThread('child_file')
        worker.postMessage(browserServer.wsEndpoint())
}

#child class:

const messageListener = async (wsEndpoint) => {
        const browser = await playwright.chromium.connect({ wsEndpoint });
        const page = await browser.newPage();
        await page.goto('https://google.com.vn');
        console.log('connected one more');
}

if (parentPort) parentPort.on('message', messageListener)

This error appears sometimes on my machine

Timeout 30000ms exceeded during chromium.connect.
================== chromium.connect logs ==================
<ws connecting> ws://127.0.0.1:52949/bb0846224122de15d13af54888055652
<ws connected> ws://127.0.0.1:52949/bb0846224122de15d13af54888055652
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.

@dgozman
Copy link
Contributor

dgozman commented Aug 19, 2020

Thank you for the repro! I tried reproducing this with worker_threads, but all 20 workers connect and navigate just fine, with playwright v1.3.0 and node v12.13.1.

const playwright = require('playwright');
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');

(async () => {
  if (isMainThread) {
    const browserServer = await playwright.chromium.launchServer();
    const workers = [];
    for (let i = 0; i < 20; i++) {
      const worker = new Worker(__filename, { workerData: i });
      worker.postMessage(browserServer.wsEndpoint());
      workers.push(worker);
    }
  } else {
    const messageListener = async (wsEndpoint) => {
      const browser = await playwright.chromium.connect({ wsEndpoint });
      const page = await browser.newPage();
      await page.goto('https://google.com.vn');
      console.log('connected one more ' + workerData);
    }
    parentPort.on('message', messageListener);
  }
})();

@phileba
Copy link
Author

phileba commented Aug 25, 2020

can you try to run in headless: false, 1 or 2 times it may appears

@pavelfeldman pavelfeldman added 1.5 and removed v1.4 labels Sep 3, 2020
@dgozman
Copy link
Contributor

dgozman commented Sep 28, 2020

can you try to run in headless: false, 1 or 2 times it may appears

Sorry, still cannot repro. Let me close this as I cannot reproduce it. Please reopen if you have a full script that does repro this.

@dgozman dgozman closed this as completed Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants