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?

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.

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?

Incidentally, I circumvented the problem by having the startup script
killing the child processes as well as the daemon, so
"/etc/rc.d/init.d/$daemon restart" would restart the daemon correctly. 

Pete


Reply via email to