cypress-io / cypress

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

Cypress 11.2.0: selectFile command to upload a huge sized file is failing in Electron browser but works fine in Chrome and Firefox #24583

Open DiwanD03 opened 1 year ago

DiwanD03 commented 1 year ago

Current behavior

I am trying to upload a large file in a web application using 'selectFile' command in cypress. Though the code works fine in chrome and firefox browser, if I select electron the browser crashes with below error:

[7898:1108/172752.248261:ERROR:node_bindings.cc(143)] Fatal error in V8: v8::ToLocalChecked Empty MaybeLocal. The Test Runner unexpectedly exited via a exit event with signal SIGSEGV

Desired behavior

The file should get successfully uploaded in electron browser too.

Test code to reproduce

cy.get('').selectFile('', { force: true, })

Cypress Version

10.4.0 11.2.0

Node version

v14.18.1

Operating System

macOS 12.6

Debug Logs

No response

Other

No response

DiwanD03 commented 1 year ago

The file being uploaded is huge in size - 422957367

If I upload a small sized file, it goes through fine in electron browser too.

DiwanD03 commented 1 year ago

Hi @nagash77, Were you able to make any progress on this issue? Checking if it is atleast reproducible in your environment.

DiwanD03 commented 1 year ago

Hi @rockindahizzy are there any updates on this issue?

DiwanD03 commented 1 year ago

Hi @nagash77 , @rockindahizzy please update on the latest status of this issue.

mike-plummer commented 1 year ago

Hi @DiwanD03 , sorry for the delay getting back to you. We've been heads down on the v12 release of Cypress for the last couple weeks.

I will try to carve out time to look into this tomorrow, but in the interim I do want to mention that we had a major upgrade to our bundled Electron in version 10.10.0 of Cypress. I would recommend upgrading to at least that version (or better yet, to v12.0.1 which we released this week) to see if that upgrade fixes your issue. Let me know if you have a chance to try that out

DiwanD03 commented 1 year ago

Hi @mike-plummer , thank you for taking this up. I did try to test the scenario using version 11.2.0 of Cypress and saw the same error as described earlier. Do let me know how it goes at your end.

mike-plummer commented 1 year ago

@DiwanD03 I did some local testing on this and reproduced the issue you've described. After doing a bit of playing around I was able to get a ~400 MB file to work, but a 408 MB file fails, and the tests fail in exactly the same way when run in open mode and headless run mode. ~This leads me to suspect it's not an inherent "Cypress is doing something wrong in Electron" issue but rather a memory limitation (headless mode should preserve more resources for internals since there's less UI going on). Based on the logging (the V8::ToLocalChecked logs you referenced and that I see as well) I'm inclined to say it's not something we have much control over since that's an internal Electron error, but I can't say that for certain. Electron recently introduced some revisions to their memory architecture (pointer compression and the memory cage, to name two) which have caused a decent number of memory issues throughout the ecosystem.~

Do you have a hard requirement to upload a 400+ MB file within an E2E test like this? It sounds like you have a workaround by using Chrome if you absolutely need to validate using the massive file, but could you restructure your test using a smaller file in order to focus your test more on the user interactions in the browser?

Update: To correct my earlier statement, I have learned that this is actually a limitation of how Cypress implements the selectFile command. Our implementation utilizes a WebSocket and marshals and dispatches the entire file in a single request which has a limit on the size of file it can support. In the interests of transparency, I'm happy to send this along to the team but it's unlikely to be prioritized in the near future since uploading a 400+ MB file is a somewhat uncommon use case.

DiwanD03 commented 1 year ago

@mike-plummer I understand now, that it's a known limitation and as you mentioned we have a workaround(using chrome) in place. Thank you for looking into this, for the detailed explanation and for re-routing it to your team for further action.

vvip-68 commented 1 year ago

Hi, all. I quite necessary to upload file about 400M (currently - 396M), but selectFile() crashes cypress app with message "Cannot create a string longer than 0x1fffffe8 characters; Error: Cannot create a string longer than 0x1fffffe8 characters"

I test webUI of my device that must accept firmware package, update and restart device with new firmware and I got error above on any browser - Chrome / FireFox / Electron.

When I put file and upload it manually all works correctly. As I understand HTML5 element do not load whole file into memory and sends content of file by chunks. So why selectFile() trying to load whole content of file as is, and if take in attention error message and stack - as base64 coded string?

Cannot create a string longer than 0x1fffffe8 characters Error: Cannot create a string longer than 0x1fffffe8 characters at Object.slice (node:buffer:655:37) at Buffer.toString (node:buffer:825:14) at i (:4457:67003) at s.exports (:4457:67130) at :4457:68422 at Array.forEach () at Object.encodePayload (:4457:68405)