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?

WBR, basiliscos.

In reply to [solved] plack: close filehandle responsibility by basiliscos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.