Node.js:EBADF,错误的文件描述符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6688552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:22:38  来源:igfitidea点击:

Node.js : EBADF, Bad file descriptor

node.jsfile-descriptor

提问by Adam

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

如果我多次重新加载我的应用程序(从带有重新加载按钮的浏览器),50 reload/10 seconds它会给我这个错误:

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

在我看来,这像是带宽错误或类似的错误,最初我在使用 HTML 5 音频 API 时遇到了错误,如果我按顺序加载了 10-15 次音频文件,那么我就会遇到错误,但是现在我发现我在没有音频 API 的情况下也通过多次重新加载站点来得到错误,而且 Safari 给我的错误比 Chrome 快得多(WTF?)

I'm using Node.js 0.4.8 with express+ jadeand I'm also connected to a MySQL database with the db-mysqlmodule.

我将 Node.js 0.4.8 与express+一起使用,jade并且我还使用该db-mysql模块连接到 MySQL 数据库。

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

我在网上找不到任何关于这个主题的文章有什么帮助,所以请让我知道什么可能导致这个错误,因为它真的很令人困惑:(

采纳答案by Peter Lyons

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

“重新加载您的应用程序”是指从浏览器刷新您的应用程序主页,还是实际上停止并重新启动 node.js 服务器进程?我假设是前者,在这种情况下,如果您不能可靠地重现它,那么调试将非常棘手,尤其是因为您没有良好的堆栈跟踪来查明来源。但是如果你使用 express.jsapp.error钩子(这里的文档) 您需要从“错误的文件描述符”错误中记录错误路径,这有望让您了解这是一个被删除的临时文件还是什么。就实际原因而言,我们只能提供猜测,因为“错误的文件描述符”是一个非常通用的低级错误,这基本上意味着您正在对不再处于正确状态的文件描述符调用操作来处理该操作(例如读取关闭的文件,打开已删除的文件等)。

回答by Thiago Duarte

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

@CIRK,看看这个: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

编辑:或者它可能与连接 1.4.3 中的此错误有关:https: //github.com/senchalabs/connect/issues/297

if this is your case, just try to upgrade it

如果是这种情况,请尝试升级它