Rayrun
← Back to Discord Forum

Javascript heap out of memory

nevermind5566posted in #help-playwright
Open in Discord
nevermind5566

I run 300 asyncio tasks, with multiple browsers contexts that visit pages at the same time. Sometimes I get this error which causes everything to crash. From what I understand, this is either a memory leak or just not having enough resources available. I am not sure whether it is a memory leak caused by me, since there is not much I am doing on my side (just visiting webpages, and yes, I do close pages after visit is completed). What happens if there is a memory leak in the JavaScript code executed by visiting one of the web pages? Is there a way to make Playwright avoid letting a webpage consume all the resources?

[240854:0x6785e40] 1640109 ms: Mark-sweep 4016.8 (4131.1) -> 4004.4 (4131.8) MB, 2680.4 / 0.4 ms (average mu = 0.086, current mu = 0.041) task; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xb7a940 node::Abort() [/home/Traffic/venv/lib/python3.10/site-packages/playwright/driver/node] (...)

This thread is trying to answer question "What happens if there is a memory leak in the JavaScript code executed by visiting one of the web pages? Is there a way to make Playwright avoid letting a webpage consume all the resources?"

2 replies

Hello, I am getting a similar error on the version 139.0

<--- Last few GCs --->
[22:0x67ad560] 89435467 ms: Scavenge 4037.8 (4120.4) -> 4037.3 (4131.2) MB, 5.8 / 0.0 ms  (average mu = 0.968, current mu = 0.213) allocation failure; 
[22:0x67ad560] 89435488 ms: Scavenge 4044.5 (4131.2) -> 4043.5 (4132.4) MB, 6.8 / 0.0 ms  (average mu = 0.968, current mu = 0.213) allocation failure; 
[22:0x67ad560] 89436176 ms: Scavenge 4045.4 (4132.4) -> 4044.4 (4153.2) MB, 683.0 / 0.0 ms  (average mu = 0.968, current mu = 0.213) allocation failure; 
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb87bc0 node::Abort() [/usr/local/lib/python3.9/site-packages/playwright/driver/node]
Aborted (core dumped)

I found a solution for this. Whoever is coming here later on - please set the NODE_OPTIONS global environment variable to 8GB or 16GB based on your memory settings which solves the problem.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.