selenium-ide: EventEmitter memory leak causing Selenium IDE crashing

🐛 Bug Report

When running test scripts for about 20-30 min with “Run” command, some memory leaks related with EventEmitter begin to appear and Selenium IDE starts lagging. Eventually after more than 30 min Selenium IDE window becomes white and window completely stops responding, some time after Selenium IDE crashes. When screen is white errors about WebFrameMain access pop up all the time in logs window and console window, if application was ran via it, until crash.

To Reproduce

Use “Run” command in cycles, which would run some script over and over again for longer time, better if different scripts are ran.

Expected behavior

I suppose program shouldn’t crash and should be able to handle script running with “Run” command many times within 1 test.

Logs

Example of memory leak error from Selenium IDE logs:

[2024-01-08 16:57:45.433] [error] (node:17880) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 state.onMutate.response listeners added to [IpcMainImpl]. Use emitter.setMaxListeners() to increase limit

End of logs from console during the crash:

14:41:38.027 > Error sending from webFrameMain:  Error: Render frame was disposed before WebFrameMain could be accessed
    at WebFrameMain.s.send (node:electron/js2c/browser_init:2:91758)
    at WebContents.send (node:electron/js2c/browser_init:2:78126)
    at C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\src\main\api\classes\EventListener.ts:107:16
    at new Promise (<anonymous>)
    at fn (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\src\main\api\classes\EventListener.ts:102:55)
    at map (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\src\main\api\classes\EventListener.ts:40:62)
    at Array.map (<anonymous>)
    at Object.dispatchEvent (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\src\main\api\classes\EventListener.ts:40:50)
    at transFn (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\src\main\log.ts:23:30)
    at i.processMessage (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\node_modules\.pnpm\electron-log@5.0.1\node_modules\electron-log\src\core\Logger.js:168:11)
    at i.logData (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\node_modules\.pnpm\electron-log@5.0.1\node_modules\electron-log\src\core\Logger.js:124:10)
    at console.<computed> [as error] (C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\node_modules\.pnpm\electron-log@5.0.1\node_modules\electron-log\src\core\Logger.js:79:37)
    at WebFrameMain.s.send (node:electron/js2c/browser_init:2:91789)
    at WebContents.send (node:electron/js2c/browser_init:2:78126)
    at C:\Users\User\AppData\Roaming\npm\node_modules\selenium-ide\build\webpack:\src\main\api\classes\EventListener.ts:107:16
    at new Promise (<anonymous>)

<--- Last few GCs --->

[14116:000017A400144000]  2842676 ms: Scavenge 3721.2 (4086.5) -> 3716.7 (4087.0) MB, 28.18 / 0.00 ms  (average mu = 0.391, current mu = 0.382) allocation failure;
[14116:000017A400144000]  2842725 ms: Scavenge 3722.7 (4087.0) -> 3718.4 (4087.3) MB, 17.62 / 0.00 ms  (average mu = 0.391, current mu = 0.382) allocation failure;
[14116:000017A400144000]  2842758 ms: Scavenge 3724.2 (4087.3) -> 3719.9 (4087.8) MB, 10.02 / 0.00 ms  (average mu = 0.391, current mu = 0.382) allocation failure;


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF7881E4BF6 node::SetTracingController+86038
 2: 00007FF7881E4E69 node::OnFatalError+585
 3: 00007FF78B3A1453 v8::Function::NewInstance+835
 4: 00007FF78B3A13E3 v8::Function::NewInstance+723
 5: 00007FF78B464AC7 v8::CppHeap::wrapper_descriptor+66519
 6: 00007FF786CDF9C8 v8::CppHeap::Terminate+91560
 7: 00007FF786CDE0D6 v8::CppHeap::Terminate+85174
 8: 00007FF786CE54DB v8::CppHeap::Terminate+114875
 9: 00007FF786CE5324 v8::CppHeap::Terminate+114436
10: 00007FF786F32B05 cppgc::internal::WriteBarrier::SteeleMarkingBarrierSlow+2677

Project file reproducing this issue (highly encouraged)

Dummy project with test created specifically to reproduce the issue (extension is changed to json to be able to upload it to GitHub). Run test “new test main”. Issue was found with more complex project, but structure of test in provided dummy project is similar. In “While” command its written 8000, but at least for me value wasn’t reaching 3k before crashing dummy tests.json

Environment

OS: Windows 10 Selenium IDE Version: 4.0.1-alpha.75-windows or higher

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 1
  • Comments: 20 (12 by maintainers)

Most upvoted comments

@edvinjunda - Thanks for the help with everything!

I guess this issue can be closed now

Maybe separate issue should be created relating selenium long-term stability problems since event emitter leaks are fixed?

@edvinjunda - I added back a set timeout clause when its retrying stuff. I found in some cases (playback of an empty click for example), this would lock the entire resource set until the binary exploded 😬 . This won’t help in the big case, but makes things a bit better in the near term.

@edvinjunda - Okay, pushing out a release now that deals with some of the hangs. The IDE handles playing suite windows better which might help a bit with preventing the IDE from going white, but I still need to do a lot more to figure out performant ways of doing writes on the logger component.

@edvinjunda - Thank you for testing and the side file. I’m going to continue to refine this week. My goal’s this week are first an issue where certain tests can rarely hang if they hit just the right issue at high parallel execution, and then this.

I think I’ve got this resolved. I changed your test script to give me the time differential after running test case 3. It’s looking good, but it’s only around 1200 atm. Should be at 8k within the hour, and then I’ll be able to let you know. But definitely better event lifecycle handling.

I just wanted to come back here and say that the side file you provided is an absolute banger 🥂

I love this issue, yeah I’ve been having this problem for a while, but having an issue about it will give me the fire I need to resolve it. Thank you for reporting! I’ll try and have some progress here this week. Thank you for the repro side file ❤️