lnl has asked for the wisdom of the Perl Monks concerning the following question:

In some of my Perl programs I use flat files, and there are lots of open and close statements, always with error handling.

99.9% of the time, all works well, but lately, I have had some failures to "close".

I'd rather handle it internally, rather than bother my customers with error messages. So, my question is: What is the best way to manage these failures in the CGI environment?

My inclination is to loop several times, with some reasonable timeout. Is there a better way?

TIA

--lnl

Replies are listed 'Best First'.
Re: Dumb Question #3 - open/close failures
by Ovid (Cardinal) on Sep 15, 2002 at 16:21 UTC

    As BrowserUk pointed out, if you let us know why the files failed to close, that would help. I'd like to add that there is no "best way to manage" this problem. It depends upon what you are trying to do, why you are trying to do it, what happens if you don't do it, etc.

    Aside answering the questions above, here are some others:

    • If you use source control, check what changes have occurred to the offending programs when the failures started to occur. Rarely do problems just "start happening".
    • Is this really a cgi environment? Any chance that it's mod_perl, ISAPI, or something else that might have a bearing on the problem?
    • Can you show us any of the offending code?
    • You mentioned that this is a recent problem. Has anything on your box changed? Is there any scheduled maintenance you skipped? I know the latter question seems weird, but if you don't know what is causing a problem, then everything is suspect.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Dumb Question #3 - open/close failures
by Zaxo (Archbishop) on Sep 15, 2002 at 15:36 UTC

    My favorite guess is that the handle is already closed. A close call can also expose errors from buffered prints.

    Check your error logs.

    After Compline,
    Zaxo

      A close call can also expose errors from buffered prints.

      This can happen when disk usage limits are strictly enforced. (I.e., "You can write only this much; you can't write no more.") And, since people almost never check errors on writes, errors go undetected until close.

Re: Dumb Question #3 - open/close failures
by BrowserUk (Patriarch) on Sep 15, 2002 at 12:51 UTC

    It would be easier to make suggestions if you told us what reason(s) Perl identifies (in $!) for the failures to close?


    Well It's better than the Abottoire, but Yorkshire!
      Yah, I shoulda printed/saved that... Now I'm waiting for the .1% of the time when it screws up.

      The error log (just one file - .6GB - for the entire server) doesn't provide any insight.

      --lnl