question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: EBADF: bad file descriptor, write

See original GitHub issue

Running version 0.3.9 of this plugin, my setup is as follows (all running in jenkins): running using docker-compose I have 1 selenium hub instance, 2 chrome nodes, 1 instance of the frontend application.

once that is running, I’m constructing multiple commands similar to:

sh 'cd /usr/src/app && ' +
   "MOCHA_E2E_PARAMS='--grep=${tag} " +
   "--rootUrl=http://frontend:3000 --seleniumServer=hub " +
   "--browserName=chrome --screenshotDir=${env.WORKSPACE}/screenshots/selenium " +
   "-C -R mocha-jenkins-reporter -O junit_report_path=${env.WORKSPACE}/tests/test-results/selenium_chrome_${tag}.xml' " +
   "yarn run mocha-e2e"

I then run these inside a docker container using parallel. This has worked well using the xunit reporter (though I had other issues with it, unrelated to the runtime itself), but ever since integrating mocha-jenkins-reporter I’m getting the following error every time a suite fails:

fs.js:793
  return binding.writeString(fd, buffer, offset, length, position);
                 ^

Error: EBADF: bad file descriptor, write
    at Error (native)
    at Object.fs.writeSync (fs.js:793:18)
    at Runner.<anonymous> (/usr/src/app/node_modules/mocha-jenkins-reporter/lib/jenkins.js:308:10)
    at emitNone (events.js:91:20)
    at Runner.emit (events.js:185:7)
    at /usr/src/app/node_modules/mocha/lib/runner.js:812:12
    at done (/usr/src/app/node_modules/mocha/lib/runner.js:649:7)
    at Runner.next [as nextSuite] (/usr/src/app/node_modules/mocha/lib/runner.js:616:16)
    at Runner.uncaught (/usr/src/app/node_modules/mocha/lib/runner.js:737:17)
    at process.uncaught (/usr/src/app/node_modules/mocha/lib/runner.js:804:10)
    at emitOne (events.js:96:13)
    at process.emit (events.js:188:7)
    at process._fatalException (bootstrap_node.js:296:26)
error Command failed with exit code 7.

After looking at the source, this comes from the following line: https://github.com/juhovh/mocha-jenkins-reporter/blob/master/lib/jenkins.js#L308

Since this is happening only after errors, I assume it’s related to the onError handler I use, which basically dumps the client console and takes a screenshot:

    onError: function (error, testTitle, done) {
        error && console.error(error);
        const activeClient = require('./setup.js').browser.activeClient();
        dumpBrowsersConsole(activeClient)
            .then(() => saveScreenshot(activeClient, testTitle.replace('/', '_')))
            .execute(`return "LOG: Ending test ${testTitle}"`)
            .end()
            .call(done)
            .call(() => {
                process.exit(1);
            });
    }

and relevant functions:

function dumpBrowsersConsole (client, excludeLevels = []) {
    return client.log('browser').then(function (logmessage) {
        logmessage.value.forEach(entry => {
            if (excludeLevels.indexOf(entry.level) <= -1) {
                console.log('> ', entry.level, '> ', entry.message.substring(0, 500));
            }
        });
        return true;
    });
}
function saveScreenshot (client, testTitle) {
    if (!fs.existsSync(screenshotDir)) {
        fs.mkdirSync(screenshotDir);
    }
    const currentTestTitle = testTitle && testTitle.replace(/\s/g, '_');
    const screenshotPath = screenshotDir + '/e2e-screenshot-' + currentTestTitle + '.png';
    console.info('Creating screenshot', screenshotPath);
    return client
        .saveScreenshot(screenshotPath);
}

Again, this never happened with the xunit reporter, and this also doesn’t happen when I try to replicate it locally. It seems like it’s coming from the writing of the xml file itself, but AFAICT the xml file is written.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jvahcommented, Mar 28, 2018

@Pourliver I tried to fix this in the latest 0.3.12 release, please try it out and let me know if it helped.

0reactions
Pourlivercommented, Mar 29, 2018

Well the fixe mutes the error, so I think we can see this as a fix 😃 Thanks for the fast reply.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: EBADF: bad file descriptor, write · Issue #250
I have an express server application that handles a few NodeJS API and hosts the Angular 10 app. In production, I use process...
Read more >
Node.js : EBADF, Bad file descriptor
This seems to me like a bandwidth error or something like that, originally I've got the error when I played with the HTML...
Read more >
Unable to write to file descriptor; EBADF error : r/rust
This returns a file descriptor. When I try to `write()` to the file via the descriptor, the program panics with error `EBADF` (invalid...
Read more >
Using npm library with Forge - App code snapshot error ...
On deploy I get this error: Error: Error thrown in the snapshot context. App code snapshot error: EBADF: bad file descriptor, Learn more...
Read more >
How to fix bad file descriptor error in VS Code? "File changes ...
I have vsc version 1.66. I'm getting the following notification: File changes watcher stopped unexpectedly. A reload of the window may ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found