puppeteer: [Bug]: Browser.close does not shutdown the process immediately

Error string

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.

Bug behavior

  • Flaky
  • PDF

Background

The code example above is a simplified version of our Lambda function. Basically. we don’t do anything tricky, only load the page, giving it reasonable time to load while monitoring the ready state of the page and its source code, and get the data from it.

The crawler works great except sometimes the browser freezes. In most cases, we catch this when closing the browser. We scrape hundreds of thousands of pages and weren’t able to make it work reliably reusing the same browser instance, even with periodical restarts. Therefore, we close and open the browser on each crawl.

At some point, it freezes on the browser.close() so we had to implement a timeout function and try to kill the process, which doesn’t work well. Even after sending the SIGKILL signal, the process stays. Probably in a zombie state or just stucks somewhere, I don’t know and we have no instruments to investigate. Must be an upstream bug in the chrome itself.

Expectation

There should be a way to get rid of a faulty process. Disregarding the nature of the failure, we should be able to kill it and start a new one.

Reality

The fact we’re sending SIGKILL and it brings us nowhere tells me the child process is spawned incorrectly and wasn’t properly detached from its parent. When something goes wrong, such processes stay as long as their parent, which can take forever as we have no control over Lambda’s lifecycle (almost). The only solution I can think of is to call exit in the main function, which will forcefully restart the Lambda. Then we handle a faulty response and restart the job.

We started seeing this problem after upgrading to 112+. We are on 122 now but the picture is the same.

Screenshot 2024-03-31 at 17 22 51

Puppeteer configuration file (if used)

No response

Puppeteer version

22.4.1

Node version

20.11.1

Package manager

npm

Package manager version

10.2.4

Operating system

Linux

About this issue

  • Original URL
  • State: open
  • Created 3 months ago
  • Comments: 16

Most upvoted comments

Thanks, I see that Browser.close sends a success response but actually does not close the browser.