Subject: | Unclosed filehandles cause trouble when forking |
Hi,
I have a CGI that uses Parse::RecDescent and then forks, closing STDOUT
and STDERR in the child, while the parent exits right way.
Well, the parent becomes a zombie and Apache waits for the child to
terminate before returning any output to the browser. This was a nasty
bug and wasn't easy to find out that Parse::RecDescent is the culprit :)
I have found a workaround: along with STDOUT and STDERR I also close
these three files belonging to Parse::RecDescent in the child code:
close(Parse::RecDescent::TRACECONTEXT);
close(Parse::RecDescent::ERROR);
close(Parse::RecDescent::TRACE);
This works for me, although it is not very But is there a better way to
close these files? Could I avoid creating them in the first place? I
have noticed that TRACECONTEXT is just a duplicate for STDERR:
open (TRACECONTEXT, ">&STDERR");
Why isn't STDERR used directly? A module should not left any files
opened or have a finalize method/destructor to close them, but I do not
know whether this is doable or not in Parse::RecDescent.
Thanks for your support.
Antonio Bonifati
http://ninuzzo.freehostia.com