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] Error when using PM2 process manager in cluster mode #4461
Comments
@rtag what do I do to reproduce this locally? I tried just running browser server and launching it with $ npx pm2 start a.js -i max and this ran just fine. |
can I get your a.js @aslushnikov CODE THAT DOES NOT WORK const http = require('http');
const playwright = require('playwright');
const browser_args = [
"--disable-gpu",
"--disable-web-security",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-sandbox",
"--no-zygote",
"--ignore-certificate-errors",
"--ignore-certificate-errors-spki-list",
"--enable-features=NetworkService",
]
const server = http.createServer(async (req, res) => {
const browserServer = await playwright.chromium.launchServer({ headless: true, ignoreHTTPSErrors: true, args: browser_args })
const wsEndpoint = (await browserServer).wsEndpoint()
console.log("wsEndpoint", wsEndpoint);
});
server.listen(6000);
console.log('Node.js web server at port 6000 is running..') |
Not sure why but under PM2 address is null @aslushnikov node_modules/playwright/lib/browserServerImpl.js this._server = new ws.Server({ port });
const address = this._server.address(); |
What I found so far is if cluster.fork() is used it breaks ws from require("ws"); @pavelfeldman . Maybe this is just a ws issue? Or I am doing something wrong? node_modules/playwright/lib/browserServerImpl.js:52 const http = require('http');
const playwright = require('playwright');
const cluster = require('cluster')
const browser_args = [
"--disable-gpu",
"--disable-web-security",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-sandbox",
"--no-zygote",
"--ignore-certificate-errors",
"--ignore-certificate-errors-spki-list",
"--enable-features=NetworkService",
]
const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.
const server = http.createServer(async (req, res) => {
const browserServer = await chromium.launchServer({ headless: true, ignoreHTTPSErrors: true, args: browser_args });
const wsEndpoint = await browserServer.wsEndpoint();
console.log(wsEndpoint);
// Use web socket endpoint later to establish a connection.
const browser = await chromium.connect({ wsEndpoint });
const context = await browser.newContext();
console.log("Number of contexts currently running in this browser: " + browser.contexts().length);
});
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
// Fork workers.
for (let i = 0; i < 4; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
// Workers can share any TCP connection
// In this case it is an HTTP server
server.listen(4000);
}
console.log('Node.js web server at port 4000 is running..')
|
I can repro this, thank you for the script. |
Context:
Code Snippet
Describe the bug
Getting error when using PM2 process manager in cluster mode, but works fine when using node to run
1|www | TypeError: Cannot read property 'port' of null
1|www | at new BrowserServerImpl (../node_modules/playwright/lib/browserServerImpl.js:52:108)
1|www | at BrowserServerLauncherImpl.launchServer (..node_modules/playwright/lib/browserServerImpl.js:41:16)
The text was updated successfully, but these errors were encountered: