appium: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

The problem

Hi,

I am currently using Appium for a test application that monitors the status of an Android smartphone. In particular my application runs for many hours and needs to collect many screenshots of the smartphone during the execution (by using the getScreenshot function).

After some hours and hundreds of screenshots collected the Appium server crashed with the following error:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

In order to reproduce the issue I guess it is enough to put the getScreenshot function in an infinite loop.

Environment

  • Appium version: 1.14.2
  • Desktop OS/version: Windows 10 1903 64 bit
  • Node.js version: 12.6.0
  • Npm or Yarn package manager:
  • Mobile platform/version under test: Android 9 Pie
  • Real device: Samsung S9
  • Additional parameters to run Appium: --relaxed-security

Link to Appium logs

I collected log output from two different crashes:

https://gist.github.com/ptagl/0c189d8343daebc22a8e580e4d02b7a1 https://gist.github.com/ptagl/a33dac0702cf55e6e5dbaeb4ae1190be

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (1 by maintainers)

Most upvoted comments

Yep, the trace look much better now. Waiting for the PR to be reviewed and polished. Thank you for the assistance

The steps I followed to take the snapshot are:

  1. Open the terminal and go to the Appium module folder (in case of Windows OS something like C:\Users\username\AppData\Roaming\npm\node_modules\appium).

  2. Run the command node --inspect . and copy the URL printed on the screen (something like ws://127.0.0.1:9229/0f2c936f-b1cd-4ac9-aab3-f63b0f33d55e).

  3. Open Edge or Chrome and browse to edge://inspect or chrome://inspect respectively. Then paste the URL (or wait for the entry to appear automatically) and press “Inspect”.

  4. In the new window go to the “Memory” tab, select “Allocation instrumentation on timeline” and check “Record allocation stacks”, then start the profiling.

  5. When you collected enough allocations or the application crashed, stop the profiling, wait for the finalization and then save to file.

  6. Optional: if the snapshot file it too big, zip it.

Published to appium@beta

@mayureshshirodkar No, the PR is still waiting for a review.

@mykola-mokhnach I tried the latest changes to the base driver and it seems much better now! I ran the test for around 3 hours, it started using 300MB or less and then it grew up very slowly reaching 800MB. After few hours I checked again and it was at 500MB, so I’m not sure if there is still some memory leak or not, but it seems like the getScreenshot command is not leaking anymore. I made the heap snapshot in case it is helpful for you.

https://we.tl/t-YPSbxMxkbl

There was known memory leak issue related to adb logs collection, which was fixed since Appium 1.15, so try to upgrade first. If the problem still happens in 1.15 then we need the heap snapshot before the OOM error happens.