zotonic/zotonic — Issue #295: Erlang and file descriptors (or: why I only got blank pages)
Author: kaos
Created: 2012-02-20 20:37:14+00:00
State: open

The resolution to this issue lies in documentation or wiki or the like, I guess.

I post it here for now to bring it to attention.
If the core dev team already was very well aware of this, I feel it's time it was communicated to the rest of the zotonic user base.

I noticed I got a lot of completely empty responses from a zotonic instance (regardless of which site I was accessing).
Looking at the logs, I found pages upon pages of errors like this:

```
=ERROR REPORT==== 20-Feb-2012::20:59:26 ===
{mochiweb_socket_server,317,{acceptor_error,{error,accept_failed}}}

=ERROR REPORT==== 20-Feb-2012::20:59:26 ===
application: mochiweb
"Accept failed error"
"{error,emfile}"

=ERROR REPORT==== 20-Feb-2012::20:59:27 ===
{mochiweb_socket_server,317,{acceptor_error,{error,accept_failed}}}

=INFO REPORT==== 20-Feb-2012::20:59:34 ===
Could not find template: article.tpl (enoent)
=ERROR REPORT==== 20-Feb-2012::20:59:34 ===
webmachine error: path="/en/article/684/chuck-moore-on-the-lost-art-of-keeping-it-simple"
{error,{throw,{error,{template_not_found,"article.tpl",enoent}},
[{z_template,render,3},
{resource_page,html,1},
{resource_page,to_html,2},
{webmachine_resource,resource_call,3},
{webmachine_resource,do,3},
{webmachine_decision_core,decision,3},
{webmachine_decision_core,handle_request,2},
{webmachine_mochiweb,loop,2}]}}
```

I know that `article.tpl` exists, so a little google to assist, turning up this nice blog post: http://metajack.im/2008/09/23/file-descriptors-are-yummy-or-common-pitfalls-of-ejabberd/

Looking at my ulimit, it says it is set to 1024, and checking how much beam has eaten up gives me slightly more...?!
```
[root@ganesha sasl]# lsof | grep beam | wc -l
1093
```

which is a considerable amount out of the total 2457 lines that lsof spits out.
I'm wondering whether there can be a fd leak...? Better keep an eye on it.

A quick reset of all beam processes trunc's it down to 114:
```
[root@ganesha sasl]# kill `pidof beam`
[root@ganesha sasl]# lsof | grep beam | wc -l
114
```

And my pages serve just fine again.