Nodejs puppeteer 运行一段时间后无法启动
Nodejs puppeteer 运行一段时间后无法启动
puppeteer 运行大概一周后,就无法再打开 chrome 进程了,在这期间会非常频繁的打开关闭 browser
重现步骤
- Puppeteer version: [email protected]
- Platform / OS version: centos7.4
- Node.js version:v12
以下为伪代码,部分业务处理已移除
try {
let proxy = await jsonUtil.getProxy();
logger.info("proxy", proxy);
let proxy_server = 'http://' + proxy.ip + ':' + proxy.port
const launch_options = {
headless: true,
ignoreDefaultArgs: ['--enable-automation', '--window-size=1440,1024',
'--proxy-server=' + proxy_server,
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
'--disable-extensions'],
dumpio: true, autoClose: true, devtools: false,
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage']
};
browser = await puppeteer.launch(launch_options);
const pages = await browser.pages();
if (common.proxyName !== null) {
await page.authenticate({username: common.proxyName, password: common.proxyPwd});
}
await page.setViewport({width: 1440, height: 1024});
await page.setDefaultNavigationTimeout(45000);
await page.goto('http://localhost:8085/crackByGt?gt=' + data.gt + "&challenge=" + data.challenge, {waitUntil: 'networkidle0'});
//Some business processing
} catch (e) {
logger.error("error", e)
} finally {
await page.close();
await browser.close();
logger.info("浏览器关闭完成")
}
除此之外,还有一个 kill 长时间未关闭的 shell 脚本,目的是杀死超过 12 小时未关闭的 chrome-linux 进程
#!/bin/bash
#please specify the process run time,which you want to kill
run_tim=12
pid=`ps -ef | grep chrome-linux | awk '{print $2}'`
for i in $pid
do
number=`ps -p $i -o etime | wc -l`
if [ $number -eq 2 ];then
tim=`ps -p $i -o etime | awk -F ":" 'NR==2{print $1}'`
if [ $tim -ge ${run_tim} ];then
kill -9 $i
fi
else
continue
fi
done
以下为错误信息:
[2021-01-17T08:00:19.648] [ERROR] jiyan - 异常 Error: Failed to launch the browser process! spawn /opt/bbd_verify_nodejs/node_modules/[email protected]@puppeteer/.local-chromium/linux-818858/chrome-linux/chrome EAGAIN
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/opt/bbd_verify_nodejs/node_modules/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dc83aca9acacb9a8b9b9ae9ce9f2e9f2ec">[email protected]</a>@puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
at ChildProcess.<anonymous> (/opt/bbd_verify_nodejs/node_modules/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="045b74717474617061617644312a312a34">[email protected]</a>@puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:185:85)
at ChildProcess.emit (events.js:311:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
[2021-01-17T08:00:19.770] [ERROR] jiyan - 异常 Error: Failed to launch the browser process!
[0117/080019.402868:FATAL:zygote_host_impl_linux.cc(174)] Check failed: process.IsValid(). Failed to launch zygote process
#0 0x5619c2f86b39 base::debug::CollectStackTrace()
#1 0x5619c2ef94c3 base::debug::StackTrace::StackTrace()
#2 0x5619c2f09c80 logging::LogMessage::~LogMessage()
#3 0x5619c2f0a84e logging::LogMessage::~LogMessage()
#4 0x5619c199c59c content::ZygoteHostImpl::LaunchZygote()
#5 0x5619c2ea476a content::(anonymous namespace)::LaunchZygoteHelper()
#6 0x5619c0f678d6 content::ZygoteCommunication::Init()
#7 0x5619c0f67fd7 content::CreateUnsandboxedZygote()
#8 0x5619c2ea3d46 content::ContentMainRunnerImpl::Initialize()
#9 0x5619c2ea1e0b content::RunContentProcess()
#10 0x5619c2ea1f5c content::ContentMain()
#11 0x5619c2ef33d2 headless::(anonymous namespace)::RunContentMain()
#12 0x5619c2ef30bc headless::HeadlessShellMain()
#13 0x5619c04f4a03 ChromeMain
#14 0x7f3f7349f555 __libc_start_main
#15 0x5619c04f482a _start
Received signal 6
#0 0x5619c2f86b39 base::debug::CollectStackTrace()
#1 0x5619c2ef94c3 base::debug::StackTrace::StackTrace()
#2 0x5619c2f866db base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x7f3f78e35630 (/usr/lib64/libpthread-2.17.so+0xf62f)
#4 0x7f3f734b3387 __GI_raise
#5 0x7f3f734b4a78 __GI_abort
#6 0x5619c2f85665 base::debug::BreakDebugger()
#7 0x5619c2f0a0f2 logging::LogMessage::~LogMessage()
#8 0x5619c2f0a84e logging::LogMessage::~LogMessage()
#9 0x5619c199c59c content::ZygoteHostImpl::LaunchZygote()
#10 0x5619c2ea476a content::(anonymous namespace)::LaunchZygoteHelper()
#11 0x5619c0f678d6 content::ZygoteCommunication::Init()
#12 0x5619c0f67fd7 content::CreateUnsandboxedZygote()
#13 0x5619c2ea3d46 content::ContentMainRunnerImpl::Initialize()
#14 0x5619c2ea1e0b content::RunContentProcess()
#15 0x5619c2ea1f5c content::ContentMain()
#16 0x5619c2ef33d2 headless::(anonymous namespace)::RunContentMain()
#17 0x5619c2ef30bc headless::HeadlessShellMain()
#18 0x5619c04f4a03 ChromeMain
#19 0x7f3f7349f555 __libc_start_main
#20 0x5619c04f482a _start
r8: 0000000000000000 r9: 0000000000000000 r10: 0000000000000008 r11: 0000000000000202
r12: 00001db7754aedc0 r13: aaaaaaaaaaaaaaaa r14: 00001db7754aedd0 r15: 00007fffdb5a2270
di: 000000000000217f si: 000000000000217f bp: 00007fffdb5a1a20 bx: 00007fffdb5a2290
dx: 0000000000000006 ax: 0000000000000000 cx: ffffffffffffffff sp: 00007fffdb5a18e8
ip: 00007f3f734b3387 efl: 0000000000000202 cgf: 0000000000000033 erf: 0000000000000000
trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.