8

I'm running a Node.js puppeteer script with pm2. It's important to keep this process stable. After 2 days of work I see 2 restarts in my pm2 stats.

I want to find out what is causing the restarts. In my error logs I see 3 main errors:

Error: Page crashed (puppeteer )
Error: Quit inactivity timeout (mysql)
or: Timed out after 30000 ms while trying to connect to Chrome! (puppeteer )

Here is my error log (I've only left the first error's full stack data, since the similar errors have the same stack)

Error: Page crashed!
    at Page._onTargetCrashed (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/puppeteer/lib/Page.js:156:24)
    at CDPSession.Page.client.on.event (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/puppeteer/lib/Page.js:132:56)
    at CDPSession.emit (events.js:198:13)
    at CDPSession._onMessage (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/puppeteer/lib/Connection.js:232:12)
    at Connection._onMessage (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/puppeteer/lib/Connection.js:119:19)
    at WebSocket.emit (events.js:198:13)
    at Receiver.receiverOnMessage (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/ws/lib/websocket.js:720:20)
    at Receiver.emit (events.js:198:13)
    at Receiver.dataMessage (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/ws/lib/receiver.js:414:14)
    at Receiver.getData (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/ws/lib/receiver.js:346:17)

Error: Page crashed!
Error: Page crashed!
Error: Page crashed!
Error: Page crashed!
{ Error: Quit inactivity timeout
    at Quit.<anonymous> (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/mysql/lib/protocol/Protocol.js:163:17)
    at Quit.emit (events.js:198:13)
    at Quit._onTimeout (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/mysql/lib/protocol/sequences/Sequence.js:124:8)
    at Timer._onTimeout (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/mysql/lib/protocol/Timer.js:32:23)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
  code: 'PROTOCOL_SEQUENCE_TIMEOUT',
  fatal: true,
  timeout: 30000 }
{ Error: Quit inactivity timeout}
Error: Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r564778
    at Timeout.onTimeout (/home/mysite/domains/mysite.xyz/laravel/robots/node_modules/puppeteer/lib/Launcher.js:296:14)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
Error: Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r564778
Error: Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r564778

How can I find out which error has caused the restart?

p.s.: Guys I've already posted the logs in my question, I know how to check the logs! Please read the question carefully!

theDavidBarton
  • 7,643
  • 4
  • 24
  • 51
hretic
  • 999
  • 9
  • 36
  • 78
  • you can check logs of your process by `pm2 log process_id`, and you can check your process_id by `pm2 list` or `pm2 l` – Tyagi Jun 27 '20 at 16:33
  • @Tyagi thanx . i already have the log as you can see i've posted the error log , problem is i dont know which error has caused the restart ... i ususally get the logs by looking inside pm2 log file .. or `pm2 logs scriptname` – hretic Jun 28 '20 at 07:55
  • Can you share your puppeteer script also in the question? (It is enough to share the parts that contain the `page.launch` and `page.goto`). I can't promise that I can give you an answer _"which error caused pm2 to restart"_ but I have a guess that your puppeteer script could confirm. – theDavidBarton Jul 04 '20 at 11:47
  • https://github.com/puppeteer/puppeteer/issues/1347 – Griffin Jul 05 '20 at 14:04
  • @hretic can you answer my comment from 2 days before please? I promise I won't answer `pm2 logs` ;P And if you are there: the Node and puppeteer version would be also extremely useful. – theDavidBarton Jul 06 '20 at 15:55

1 Answers1

0

To check the logs of why the process has restarted you can try multiple ways:

  1. pm2 logs fileName.js

  2. Register exceptionHandlers for Node.js process for catching different exceptions.

Reference: https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly

  1. check the logs in the system for that process based on process id.