Solved! The root reason was in wrong DB-access: I use 'moo' to and always re-use the cached DB-connection, instead of creating new one on demand. (And "indirectly" closing it after serving the request). I actually used SQLite, so after heavy usage of it, it internally used filehandles and didn't closed them, so I got my error after some time.
Thanks all for answers.
The correct answer to my initial question is: indeed, I'm responsible for closing filehandle, but Path::Tiny does the right thing (DWIM) it closes the filehandle when it is no longer used; hence, my code sample provided here is valid.
Hello dear monks!
I'm using Kelp, which is very Plack-centered framework.
I have the following code for rendering icons:
use Path::Tiny; ... my $image = path($self->config('storage'), $domain_id, "icon-${size}.i +co"); ... return $self->res->set_content_type('image/x-icon') ->render_binary($image->filehandle('<', ':raw'));
After some time of execution under plackup I got the following error:
Error open (<:raw) on \'storage/3/icon-256.ico\': Too many open files at ...
Why so? I looked at Kelp::Request sources, and it just transfers the filehandle for Plack. Why Plack does not closes it after rendering the requests?
Yes, I know that I could do something like:
return $self->res->set_content_type('image/x-icon') ->render_binary($image->slurp);
but this is counter-effective a little bit? sendfile(2) cannot be used by server, and why at all I should load the whole image into perl, while actually i don't need it?
In reply to [solved] plack: close filehandle responsibility by basiliscos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |