microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.95k stars 3.67k forks source link

[BUG] Crashes when trying to launch more than 6 instances #4172

Closed iyakhiev closed 4 years ago

iyakhiev commented 4 years ago

Context:

Code Snippet

Here is how I launch my browser:

const { chromium } = require('playwright-chromium')

class MyClass {
    ...
    this.browser = await chromium.launch({  
        headless: false, slowMo: 50,
        proxy: { server: proxyUrl, username: $proxy_user, password: $proxy_pass, }
    })
    this.context = await this.browser.newContext({})
    this.page = await this.context.newPage()
    ...
}

Describe the bug

I have a loop creating instances of the class and starting playwright. Everything works just fine with 1-2-3 instances, but whole script crashes on launching of the 7-8th. Resources allows to launch more and I used to run 50 instances on the previous hosting with weaker set.

Tested several times and get 2 errors usually:

Error 1

projectDir/node_modules/playwright-chromium/lib/client/connection.js:138
            throw new Error(`Cannot find parent object ${parentGuid} to create ${guid}`);
            ^

Error: Cannot find parent object BrowserContext@542efe1178d54357c723ec96e9394def to create Frame@38a1562630571f41c86fea49af0a4b24
    at Connection._createRemoteObject (projectDir/node_modules/playwright-chromium/lib/client/connection.js:138:19)
    at Connection.dispatch (projectDir/node_modules/playwright-chromium/lib/client/connection.js:105:18)
    at Immediate.<anonymous> (projectDir/node_modules/playwright-chromium/lib/inprocess.js:40:85)
    at processImmediate (internal/timers.js:461:21)

Error 2

(node:3984) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.getVersion): Target closed.
=========================== logs ===========================
<launching> /home/snkrs/.cache/ms-playwright/chromium-815036/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-zBrnqt --remote-debugging-pipe --no-sandbox --proxy-server=http://176.103.93.10:52336 --no-startup-window
<launched> pid=5171
[err] [5171:5171:1017/093314.578152:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5192:1017/093314.578148:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5180:1017/093314.578416:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5171:1017/093314.579356:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5192:1017/093314.580570:ERROR:zygote_communication_linux.cc(143)] Did not receive ping from zygote child
[err] [5173:5173:1017/093314.580565:ERROR:zygote_linux.cc(607)] Zygote could not fork: process_type gpu-process numfds 4 child_pid -1
[err] [5173:5173:1017/093314.580781:ERROR:zygote_linux.cc(271)] Unexpected real PID message from browser
[err] [5171:5178:1017/093314.585120:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5177:1017/093314.587851:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5177:1017/093314.589657:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5171:1017/093314.589752:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
[err] [5171:5171:1017/093314.592222:ERROR:platform_thread_posix.cc(135)] pthread_create: Resource temporarily unavailable (11)
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
    at Connection.sendMessageToServer (projectDir/node_modules/playwright-chromium/lib/client/connection.js:69:15)
    at Proxy.<anonymous> (projectDir/node_modules/playwright-chromium/lib/client/channelOwner.js:54:53)
    at projectDir/node_modules/playwright-chromium/lib/client/browserType.js:62:73
    at BrowserType._wrapApiCall (projectDir/node_modules/playwright-chromium/lib/client/channelOwner.js:80:34)
    at BrowserType.launch (projectDir/node_modules/playwright-chromium/lib/client/browserType.js:53:21)
    at MyClass.initBrowser (projectDir/MyClass.js:108:33)
    at MyClass.start (projectDir/MyClass.js:37:14)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:3984) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3984) [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.
pavelfeldman commented 4 years ago

Some relevant info: https://unix.stackexchange.com/questions/253903/creating-threads-fails-with-resource-temporarily-unavailable-with-4-3-kernel

Why do you run more than one browser, do you need different proxies for each instance?

iyakhiev commented 4 years ago

Some relevant info: https://unix.stackexchange.com/questions/253903/creating-threads-fails-with-resource-temporarily-unavailable-with-4-3-kernel

Why do you run more than one browser, do you need different proxies for each instance?

I need different service accounts and proxies too. Thank you for info, I will try out it and reply

pavelfeldman commented 4 years ago

I don't think this is actionable on our side atm. We have a per-context proxy in the works, no ETA though.