On Mon, Sep 09, 2002 at 11:32:55AM -0400, Peter Chen wrote:
> Is there a way to specify the socket option close-on-exec for sockets
> created by PoCo::TCP::Server, or some how close the corresponding file
> descriptor in the child processes?
The documentation for $^F leads me to believe that Perl is setting
close-on-exec for most file handles. We can work around it, at least
for sockets, by explicitly setting close-on-exec within SocketFactory.
> I have encountered some situations, where after the daemon crashes, one
> of its children created via POE::Wheel::Run is still left running
> (unintentionally) and held on to the sockets created by the parent. The
> daemon uses PoCo::TCP::Server. So the file descriptors for the sockets
> created by PoCO::TCP::Server were leaked into the children. As long as
> one of the children is still running, attempts to restart the daemon
> would fail because it couldn't bind to the port which is still bound to
> the socket being held by the children.
POE 0.22 has code to reap child processes after its main loop exits.
It can't do that, however, if it crashes. This is a good case for
wrapping event handler execution in eval{} like the POE::Exceptions
extension does.
> One way to solve this as suggested, is to set the socket option
> close-on-exec for the sockets that are not intended to be inherited by
> child processes. This will work for POE::Wheel::Run as long as the
> "program" executed is in the forms of:
>
> Program => "shell command"
> Program => \@shell_command
>
> During testing, I find that it does not work for the form:
>
> Program => \&function
>
> This seems to make sense since running a Perl function inside the child
> process does not require another exec. However, this does create an
> interesting problem, now close-on-exec on sockets has no effect because
> an exec never takes place.
>
> So how does one prevent file descriptors from leaking into child
> processes created by POE::Wheel::Run?
POE::Wheel::Run will need to close file descriptors > $^F itself when
called in Program => \&function. That could be expensive, though.
-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net