Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js : EBADF, Bad file descriptor

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 :(

like image 857
Adam Halasz Avatar asked Jul 14 '11 04:07

Adam Halasz


1 Answers

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).

like image 144
Peter Lyons Avatar answered Oct 13 '22 21:10

Peter Lyons