adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js
https://gitter.im/mochawesome/general
MIT License
1.06k stars 160 forks source link

Error: EBADF: Closing file descriptor on garbage collection failed #363

Closed davidbasalla closed 2 years ago

davidbasalla commented 2 years ago

Describe the bug

When using the "Spec to STDOUT, produce a combined Mochawesome JSON file" config from the Cypress docs, we are seeing the test runs fail after an arbitrary number of tests (we have 30 tests in 7 files in total).

  Running:  examples/login_page.js                                                          (3 of 7)

[Error: EBADF: Closing file descriptor 110 on garbage collection failed, close
] {
  errno: -9,
  code: 'EBADF',
  syscall: 'close'
}
Error: EBADF: Closing file descriptor 110 on garbage collection failed, close
[42:1104/125012.598646:FATAL:scoped_file.cc(43)] Check failed: . : Bad file descriptor (9)
The Test Runner unexpectedly exited via a exit event with signal SIGTRAP

Code Reproduce

We're invoking our test runs with:

docker-compose exec cypress bash -c "yarn && cypress run --reporter mochawesome --reporter-options reportDir="cypress/results",overwrite=false,html=false,json=true "

I haven't had time to try to recreate this in a toy example yet. Will update here if I do.

Expected behavior

All tests should run until the end, and should emit one log file per file

Screenshots N/A

Environment (please complete the following information):

Additional context

We recently upgraded from "mochawesome": "6.2.2" to "mochawesome": "^7.0.0" and did not have this problem before.

From playing around with it, the problem seems to be caused by overwrite=false. I've tried replacing with timestamp=true and everything worked as expected.

byg0n3 commented 2 years ago

Experiencing the same issue on amplify and locally:

    "mocha": "^9.1.3",
    "mochawesome": "^7.0.0",
    "mochawesome-merge": "^4.2.0",
    "mochawesome-report-generator": "^6.0.0",
adamgruber commented 2 years ago

I'll need an example or instructions to reproduce the issue. Also please indicate the version of Node.

Keysox commented 2 years ago

We're also seeing the same issue with Node v16.7.0

adamgruber commented 2 years ago

When overwrite is set to false, fsu.writeFileUnique is called to output unique files instead of fs.outputFile (which comes from fs-extra). The fsu dependency was updated in mochawesome v7 which makes me think that could be where the root issue lies. The fsu package was changed in v2 to support async/await. The previous version of mochawesome would wrap the (non-async) fsu.writeFileUnique call in a Promise.

I can confirm this issue is not present when simply using mocha by itself but it does exist when using Cypress. I do not know enough about the inner workings of Cypress to determine the root problem.

tit commented 2 years ago

I'll need an example or instructions to reproduce the issue

@adamgruber, I have created a reproducible example in https://github.com/tit/mochawesome-issue-363

[80459:1105/003438.711329:FATAL:scoped_file.cc(43)] Check failed: . : Bad file descriptor (9)
The Test Runner unexpectedly exited via a exit event with signal SIGTRAP

Versions

$ node --version                              
v16.11.1
$ cypress --version                               
Cypress package version: 8.7.0
Cypress binary version: 8.7.0
Electron version: 14.1.0
Bundled Node version: 14.17.0
$ npm --version                               
8.0.0
$ npm list mochawesome
cypress-playground@ /Users/sergeyblohin/incountry/cypress-playground
└── mochawesome@7.0.0
adamgruber commented 2 years ago

Fix has been released in mochawesome v7.0.1