Node.js : EBADF, Bad file descriptor
Asked Answered
O

3

15

If I reload my application (from the browser with the reload button) a lots of times like 50 reload/10 seconds it gives me this error:

events.js:45
    throw arguments[1]; // Unhandled 'error' event
                   ^
Error: 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 5 Audio API, and If I loaded the audio file 10-15 times sequentially then I've got the error, but now I've discovered that I get the error without the Audio API too just by reloading the site a lots of times, also Safari gives me the error much faster than Chrome (WTF?)

I'm using Node.js 0.4.8 with express + jade and I'm also connected to a MySQL database with the db-mysql module.

I can't find any articles on the web about this topic what helps, so pleeease let me know what can cause this error because it's really confusing :(

Oshinski answered 14/7, 2011 at 4:39 Comment(0)
B
8

By "reload your application" do you mean refresh your app's home page from a browser, or actually stop and restart the node.js server process? I assume the former, in which case if you can't reliably reproduce this it will be pretty tricky to debug, especially since you don't have a good stack trace to pinpoint the source. But if you use the express.js app.error hook (docs here) you'll want to log the error path from the "Bad file descriptor" error, which should hopefully clue you in to whether this is a temporary file that got deleted or what. In terms of the actual cause, we can only offer guesses since "Bad file descriptor" is a very generic low level error that basically means you are calling an operation on a file descriptor that is no longer in the correct state to handle that operation (like reading a closed file, opening a file that has been deleted, etc).

Bornie answered 14/7, 2011 at 5:32 Comment(0)
B
0

@CIRK, take a look at this: https://github.com/joyent/node/issues/1189

it's not a node problem, but a system tuning issue.

edit: or maybe it's related to this error in connect 1.4.3: https://github.com/senchalabs/connect/issues/297

if this is your case, just try to upgrade it

Beckett answered 28/7, 2011 at 1:24 Comment(0)
C
0

This error may result from using fs to save a file whose name is a number rather than a string. File names must be strings:

Incorrect:

const fileName = 12345;
const fileContent = "The great croissant."

fs.writeFileSync(fileName, fileContent);

Correct:

fs.writeFileSync(`${fileName}`, fileContent);

Also correct:

const fileName = "12345";
fs.writeFileSync(fileName, fileContent);
Chirography answered 11/1, 2023 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.