cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.7k stars 3.16k forks source link

Having thousands of browser profiles from previous runs causes Cypress to spawn thousands of subprocesses #30043

Open WeisSebastian opened 1 month ago

WeisSebastian commented 1 month ago

Current behavior

On one of our jenkins nodes we currently have an issue that browser profiles do not get deleted (Why that happens is not part of this issue).

Currently we are in the thousands of profiles being located in the App Data directory. Now everytime we start cypress with cypress run, cypress tries to spawn thousands (highest i've seen was over 2000) Powershell subprocesses, quickly eating all available system memory

Relevant debug log: cypress.log

Desired behavior

Cypress should not spawn thousands of subprocesses consuming all system resources.

Of course there is an easy work around, delete profiles of previous runs, but if this fails somehow i'd still expect cypress to not behave in this way

Test code to reproduce

No easy reproducer

Cypress Version

13.13.2

Node version

20.16.0

Operating System

Windows 11

Debug Logs

No response

Other

No response

jennifer-shehane commented 1 month ago

@WeisSebastian Oh wow, yah, we haven't actually seen this before. 😬 Relevant logs during cypress run below.

Yah I mean the workaround at the moment would be to manually clear this folder before running this command.

cypress:server:profilecleaner found 0 root level profile matches: []
cypress:server:profilecleaner found 1444 profile folders:
..
...printed thousand+ process
...
cypress:server:util:process_profiler error running process profiler: 
  Error: expected to find current pid in process list 73944 
    at i (<embedded>:202:123157) 
    at a (<embedded>:202:123199) 
    at h (<embedded>:2798:30456) 
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Warning: We failed to remove old browser profiles from previous runs.

This error will not affect or change the exit code.

Error: Command 'Get-CimInstance -className win32_process | select Name,ProcessId,ParentProcessId,CommandLine,ExecutablePath' terminated with code: 1
   at ChildProcess.<anonymous> (<embedded>:1054:59995)
  at ChildProcess.emit (node:events:514:28)
  at maybeClose (node:internal/child_process:1091:16)
  at Socket.<anonymous> (node:internal/child_process:449:11)
  at Socket.emit (node:events:514:28)
  at Pipe.<anonymous> (node:net:323:12)

When you run Cypress, this error is being thrown within this function in our code. This code hasn't been touched in a while.

https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/browsers/utils.ts#L123

Likely there's something about the path to the profiles that is not matching our expected logic. Do you move any files/browser locations or anything around in your machine?

WeisSebastian commented 1 month ago

No, we are not moving anything around on the machine. All the old profiles are where cypress finds them and they are in the same location on my personal machine where cypress succeeds in deleting them before runs