in reply to [solved] plack: close filehandle responsibility

Let me clarify the question: who is responsible for closing the filehandle? My code, framework (Kelp) or Plack?

WBR, basiliscos.
  • Comment on Re: plack: close filehandle responsibility

Replies are listed 'Best First'.
Re^2: plack: close filehandle responsibility (everybody)
by Anonymous Monk on May 07, 2015 at 01:39 UTC

    Let me clarify the question: who is responsible for closing the filehandle? My code, framework (Kelp) or Plack?

    Everybody is responsible :)

    You assume the problem is with Kelp or Plack but you haven't ruled out your own code; you always have to rule out your own code first

    If you can write a minimal Kelp app serving files that runs out of filehandles, only then can you assume there is a problem with Kelp or Plack, until then you should assume the problem is with your code

    The problem is not with Kelp::Response::render_binary as it doesn't leave handles open.

    It hands the handle to Plack::Response::body, and eventually sub response_cb in Plack::Util which reads from the handle and then closes the handle.

     

    On a side note, if don't already know, you should ignore flushells the troll

Re^2: plack: close filehandle responsibility
by locked_user sundialsvc4 (Abbot) on May 07, 2015 at 01:01 UTC

    Questions of this nature can be pretty-much categorically answered:   “it must be You!”

    • “Plack is a plumber,” solely responsible for getting a request delivered from Apache to you, and a subsequent response delivered from you to Apache.   No smoking-gun here...
    • Kelp, likewise, is a framework:   “generically” engineered to taking care of “whatever is ‘generic,’” so that you don’t have to.
    • ... which leaves:   you.   Your application must be prepared to handle many (thousands of?) requests without “leaking.”   (It can, to a certain extent, “take the easy way out” by asking the PSGI manager to arrange for you to “commit hari-kiri” after so-many requests, but that is a crutch.)   You should always assume that you are responsible for closing all resources.