basiliscos has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: plack: close filehandle responsibility
by Anonymous Monk on May 05, 2015 at 18:29 UTC | |
|
Re: plack: close filehandle responsibility
by Anonymous Monk on May 05, 2015 at 23:15 UTC | |
by Anonymous Monk on May 06, 2015 at 00:07 UTC | |
|
Re: plack: close filehandle responsibility
by basiliscos (Pilgrim) on May 06, 2015 at 11:44 UTC | |
by Anonymous Monk on May 07, 2015 at 01:39 UTC | |
by locked_user sundialsvc4 (Abbot) on May 07, 2015 at 01:01 UTC | |
|
Re: plack: close filehandle responsibility
by RonW (Parson) on May 06, 2015 at 20:44 UTC | |
by Anonymous Monk on May 07, 2015 at 01:51 UTC | |
by RonW (Parson) on May 07, 2015 at 02:19 UTC | |
by Anonymous Monk on May 07, 2015 at 02:44 UTC |