Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress cannot delete profileDir on exit because it creates files with only read permissions. #31300

Open
ValJed opened this issue Mar 17, 2025 · 12 comments
Labels
browser: firefox stage: needs investigating Someone from Cypress needs to look at this

Comments

@ValJed
Copy link

ValJed commented Mar 17, 2025

Current behavior

Whenever I run tests on a specific browser, I get the linked error when stopping the process.

So pretty clear, it just has no permission to delete some files it created earlier. So I have to do it manually then it works again.

The problem is that even if I change manually the permissions of the entire folder, cypress creates files with only read permission:

~/.config/Cypress/cy/production/browsers/firefox-stable/interactive/CypressExtension
Image

So later, it's unable to delete them.

I'm not sure what I can do to change this behavior. Also I'm wondering why putting these files into .config when it's seems like cache files to me?

Is this problem linked to the fact that I use CYPRESS_RUN_BINARY?

Thanks in advance for any input.

Desired behavior

Cypress should create files with delete permission to be able later to delete them.

Test code to reproduce

Nothing special except I use CYPRESS_RUN_BINARY that runs a binary from nix.

Cypress Version

13.17.0

Node version

v20.18.3

Operating System

nix (Nix) 2.24.12

Debug Logs

[firefox-profile] cannot delete profileDir on exit /home/jed/.config/Cypress/cy/production/browsers/firefox-stable/interactive Error: EACCES: permission denied, unlink '/home/jed/.config/Cypress/cy/production/browsers/firefox-stable/interactive/CypressExtension/background.js'
    at unlinkSync (node:fs:1883:3)
    at _unlinkSync (node:internal/fs/rimraf:214:14)
    at rimrafSync (node:internal/fs/rimraf:195:7)
    at node:internal/fs/rimraf:253:9
    at Array.forEach (<anonymous>)
    at _rmdirSync (node:internal/fs/rimraf:250:7)
    at rimrafSync (node:internal/fs/rimraf:193:7)
    at node:internal/fs/rimraf:253:9
    at Array.forEach (<anonymous>)
    at _rmdirSync (node:internal/fs/rimraf:250:7)
    at rimrafSync (node:internal/fs/rimraf:193:7)
    at Object.rmSync (node:fs:1278:10)
    at v._cleanOnExit (<embedded>:777:119095)
    at process.onExit (<embedded>:777:117974)
    at process.emit (node:events:526:35)
    at App.<anonymous> (node:electron/js2c/browser_init:2:119065)
    at App.emit (node:events:514:28)
    at Immediate.<anonymous> (<embedded>:3024:99555)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -13,
  syscall: 'unlink',
  code: 'EACCES',
  path: '/home/jed/.config/Cypress/cy/production/browsers/firefox-stable/interactive/CypressExtension/background.js'
}

Other

No response

@ValJed ValJed changed the title Cypress cannot delete profileDic on exit because it creates files with only read permissions. Cypress cannot delete profileDir on exit because it creates files with only read permissions. Mar 17, 2025
@jennifer-shehane
Copy link
Member

@ValJed Could you try updating to latest in Firefox and see if this issue still persists? We made a lot of changes to how we interact with Firefox in 14.1.0 and I just want to see if this may already be fixed. Thanks!

@jennifer-shehane jennifer-shehane added the stage: awaiting response Potential fix was proposed; awaiting response label Mar 17, 2025
@ValJed
Copy link
Author

ValJed commented Mar 17, 2025

@jennifer-shehane Thanks for the quick feedback, cypress 14 is still not available on nix but I'll try as soon as I can.
Note that I have the same issue with chromium (with no clear error in console) but not with electron.

In the case of firefox and chromium I can fix it by manually deleting the content of ~/.config/Cypress/cy/production/browsers/** before to rerun cypress open.

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Mar 17, 2025

This is very similar to the issue on Windows with the same error message

Reproducible with Cypress 14.2.0 on Windows 11 24H2 with Firefox 136.0.1 and Node.js 22.14.0 LTS

git clone --branch firefox-profile https://github.com/MikeMcC399/cypress-test-tiny
cd cypress-test-tiny
npm ci
./firefox-loop.sh

Log example

[firefox-profile] cannot delete profileDir on exit C:\Users\mikem\AppData\Roaming\Cypress\cy\production\browsers\firefox-stable\run-18740 Error: EPERM: operation not permitted, unlink 'C:\Users\mikem\AppData\Roaming\Cypress\cy\production\browsers\firefox-stable\run-18740\rust_mozprofileKcfsDG\favicons.sqlite-shm'
    at unlinkSync (node:fs:1885:11)
    at _unlinkSync (node:internal/fs/rimraf:216:14)
    at fixWinEPERMSync (node:internal/fs/rimraf:308:5)
    at rimrafSync (node:internal/fs/rimraf:202:14)
    at node:internal/fs/rimraf:255:9
    at Array.forEach (<anonymous>)
    at _rmdirSync (node:internal/fs/rimraf:252:7)
    at fixWinEPERMSync (node:internal/fs/rimraf:306:5)
    at rimrafSync (node:internal/fs/rimraf:202:14)
    at node:internal/fs/rimraf:255:9
    at Array.forEach (<anonymous>)
    at _rmdirSync (node:internal/fs/rimraf:252:7)
    at fixWinEPERMSync (node:internal/fs/rimraf:306:5)
    at rimrafSync (node:internal/fs/rimraf:202:14)
    at Object.rmSync (node:fs:1263:10)
    at v._cleanOnExit (<embedded>:1011:95941)
    at process.onExit (<embedded>:1011:94820)
    at process.emit (node:events:530:35)
    at App.<anonymous> (node:electron/js2c/browser_init:2:127161)
    at App.emit (node:events:518:28)
    at g (<embedded>:2886:2340)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'unlink',
  path: 'C:\\Users\\mikem\\AppData\\Roaming\\Cypress\\cy\\production\\browsers\\firefox-stable\\run-18740\\rust_mozprofileKcfsDG\\favicons.sqlite-shm'
}

@jennifer-shehane jennifer-shehane added stage: needs investigating Someone from Cypress needs to look at this and removed stage: awaiting response Potential fix was proposed; awaiting response labels Mar 18, 2025
@AtofStryker
Copy link
Contributor

@ValJed thank you for opening an issue! We currently don't modify the copied extension directory contents except for background.js. I am working on building a Cypress pre-release binary that you and @MikeMcC399 can try that might resolve the issue. Right now its a bit aggresive, but its giving read, write, and execute permissions to the extension directory when we copy it over. Binaries should be available on this commit shortly. Are you both able to give the binary a try?

@AtofStryker AtofStryker self-assigned this Mar 18, 2025
@AtofStryker AtofStryker linked a pull request Mar 18, 2025 that will close this issue
3 tasks
@MikeMcC399
Copy link
Contributor

@AtofStryker

The beta binary doesn't resolve the issue unfortunately. Perhaps it is a timing issue since in some runs there was no issue, and then in others it failed to delete the profile on exit.

These are my steps:

git clone --branch firefox-profile https://github.com/MikeMcC399/cypress-test-tiny
cd cypress-test-tiny
npm ci
./firefox-loop.sh # fails sporadically
npm install npm install https://cdn.cypress.io/beta/npm/14.2.1/win32-x64/chore/FF-investigation-6286411864a452664012a221430bc3af8e10e0f4/cypress.tgz
./firefox-loop.sh

with logs attached:

firefox-cypress-31300.log

@MikeMcC399
Copy link
Contributor

@AtofStryker

This original issue from @ValJed is for Nix, which has its own special challenges. My repro is on Windows and on Linux it works fine. I think there are perhaps two related problems, so I'm going to submit a new issue for Windows.

From previous issues, I know that it is difficult for NixOS users to update, so that would be another reason to split the troubleshooting.

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Mar 19, 2025

Windows is showing the following, which is a different errno from the one in this issue (errno: -13)

  errno: -4048,
  code: 'EPERM',
  syscall: 'unlink',

@AtofStryker AtofStryker removed their assignment Mar 19, 2025
@ValJed
Copy link
Author

ValJed commented Mar 20, 2025

Hey @AtofStryker thanks for your investigation.
I can surely test on my own, I'm not sure the binary is still avaiable on the PR you linked (which is closed now) or I didn't find it.
Let me know, thanks!

@MikeMcC399
Copy link
Contributor

@ValJed

Hey @AtofStryker thanks for your investigation. I can surely test on my own, I'm not sure the binary is still avaiable on the PR you linked (which is closed now) or I didn't find it. Let me know, thanks!

You can find the binaries on 6286411#comments

I'm not sure if @AtofStryker is still waiting for feedback on this one though.

@AtofStryker
Copy link
Contributor

Hey @AtofStryker thanks for your investigation. I can surely test on my own, I'm not sure the binary is still avaiable on the PR you linked (which is closed now) or I didn't find it. Let me know, thanks!

@ValJed the binaries would be available in the comments of 6286411#comments. I closed the PR since the binaries built and we need a PR to run CI

@ValJed
Copy link
Author

ValJed commented Mar 21, 2025

@AtofStryker Ok I tried to test but I don't think this is the right binary since it's node code.
As I stated I have cypress globally installed through Nix.

I tried running it with the variable:
CYPRESS_RUN_BINARY=/home/user/Downloads/package/bin/cypress
I got

Could not run binary set by environment variable: CYPRESS_RUN_BINARY=/home/user/Downloads/package/bin/cypress

Ensure the environment variable is a path to the Cypress binary, matching **/Cypress

----------

Platform: linux-x64 (Ubuntu - )
Cypress Version: 13.17.0

I tried simply renaming the binary with a capital C Cypress.

I got

No version of Cypress is installed in: /home/user/Downloads/package/bin

Please reinstall Cypress by running: cypress install

----------


Cannot read binary version from: /home/user/Downloads/package/bin/resources/app/package.json

----------

Platform: linux-x64 (Ubuntu - )
Cypress Version: 13.17.0

@MikeMcC399
Copy link
Contributor

@ValJed

The binaries have the version 14.2.1

npm install https://cdn.cypress.io/beta/npm/14.2.1/linux-x64/chore/FF-investigation-6286411864a452664012a221430bc3af8e10e0f4/cypress.tgz

Unfortunately I don't know if you can directly use this under NixOS, since the Nix organization repackages Cypress. You might need to go through the packaging process to integrate the binary I guess.

It looks like you are using Cypress 13.17.0 from the nixpkgs so-called unstable release.
https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=cypress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser: firefox stage: needs investigating Someone from Cypress needs to look at this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants