Subject: | Proc::Daemon's intermediate process runs DESTROY() on objects |
Date: | Mon, 19 Dec 2011 01:13:53 -0500 |
To: | bug-Proc-Daemon [...] rt.cpan.org |
From: | Michael Conrad <mconrad [...] intellitree.com> |
I've run into a rather serious bug when using Proc::Daemon to spawn off
jobs from a main process (i.e. when using the return value of Init and
not exiting)
When Proc::Daemon calls "exit" in the intermediate process that it
creates ("first child"), all of the perl objects are still present in
that process, and calling exit will cause their destructors to run,
possibly doing things like closing database connections, removing
lockfiles, and all sorts of other side effects. Also, any buffered I/O
would get flushed from both the intermediate process and the parent.
I would suggest replacing "exit" with "exec '/usr/bin/true';" or
something similar. Maybe to remain the most platform-agnostic you could
"exec '/bin/sh', '-c', 'exit';". There maybe be other ways to ask the
perl interpreter to exit without running any cleanup. (actually,
POSIX::_exit(0) might do it? )
This is of course only necessary if the parent process intends to keep
running.
Thanks!
-Mike