2

I am getting the following very annoying error:

Error: EMFILE, too many open files '/home/savagegames.net/views/index.jade'
at Object.openSync (fs.js:240:18)
at Object.readFileSync (fs.js:128:15)
at View.contents (/home/savagegames.net/node_modules/express/lib/view/view.js:121:13)
at Function.compile (/home/savagegames.net/node_modules/express/lib/view.js:68:45)
at ServerResponse._render (/home/savagegames.net/node_modules/express/lib/view.js:417:18)
at ServerResponse.<anonymous> (/home/savagegames.net/node_modules/express/lib/view.js:318:17)
at /home/savagegames.net/node_modules/express-mongoose/index.js:45:21
at resolve (/home/savagegames.net/node_modules/express-mongoose/index.js:75:12)
at ServerResponse.expressmongoose [as render] (/home/savagegames.net/node_modules/express-mongoose/index.js:37:12)
at /home/savagegames.net/controllers/index_controller.coffee:49:18

I believe it is a problem with Express; how can I remedy it? Thanks.

Ian Macalinao
  • 1,608
  • 3
  • 20
  • 30
  • 1
    What's the result of `ulimit -n` run via the same way your application is started? Perhaps the limit is way too low and needs to be raised. (Contact your admin.) Perhaps there is a bug in the application and it does not close files it no longer needs. Check also `/proc/pid/fd/` directory to see the files that this process has open -- that may help you discover the problem. – sarnold Jun 29 '12 at 01:38
  • ulimit -n is `1024`. I looked at my `/proc/pid/fd` and found a ton of `lrwx------ 1 root root 64 Jun 29 03:49 276 -> socket:[619284773]`. Where would these come from? – Ian Macalinao Jun 29 '12 at 01:51
  • Those sockets are probably TCP/IP connections; check `netstat -anp | grep pid` to find out more details about those connections. (They _could_ also be Unix domain sockets; if so, `lsof` would be more useful.) – sarnold Jun 29 '12 at 01:53
  • Holy crap (excuse my language), I'm being blasted with connections. [http://pastebin.com/8zgVhkAD](http://pastebin.com/8zgVhkAD) Is this a DoS? If it isn't i must sound very stupid. – Ian Macalinao Jun 29 '12 at 01:57
  • In the small snippet there, you've got connections from three hosts; two are anonymizers from `ccc.de` and one anonymizer from `foebud.org`. They may represent dozens of users or perhaps a handful of users -- if their proxy is poorly configured. You may wish to work with the `ccc.de` people to try to see why their connections remain connected? (_Maybe_ it is something you can modify on your end to disconnect connections when users go away, but it would be odd if `node` doesn't handle that well already.) What kind of connect rates are you seeing? – sarnold Jun 29 '12 at 02:13
  • I don't think it's a handful of users; I only launched my very small website an hour ago. I checked iptraf and I'm only sending about 40kb/s outgoing. This is very, very weird. :/ – Ian Macalinao Jun 29 '12 at 03:27

2 Answers2

1

From what I found, it happens when some error happens, and some files aren't closed (of course this is a bug). In my case, node-postgres errors caused (miracleously) depletion of available descriptors. When I removed the code that caused db error, the EMFILE dissapears.

I suppose it could be fixed in the node.js code - it should close file objects when garbage collecting. Though it might happen that these lost file descriptors are still locked alive by something else.

sergeych
  • 791
  • 7
  • 11
1

I went through lot of resources , but the relevant answers is in the docs of express:

app.enable('view cache')

It really helped alot , especially lot of cache hits explains , it doesn't open the file at all.

Ashok Mandal
  • 278
  • 2
  • 13