Subject: | Wishlist: A way to stop sessions |
Currently there is no way to stop a session cleanly.
The reasons for doing this involve shutting down a specific session and it's subsessions if
they are misbehaving, and freeing the resources they use, when it does not provide an API to
be shutdown or if it's internal state is buggy.
Currently POE::NFA and POE::Component::Supervisor would benefit from this functionality.
For POE::Component::Supervisor this is required to ensure that a component can be
restarted after crashing. Currently POCO::Supervisor violates POE's internals by using an
private api to accomplish this.
The code I use right now is:
my @sessions;
my $peek = POE::API::Peek->new;
while ( my $s = shift @roots ) {
push @roots, $peek->get_session_children($s);
push @sessions, $s;
}
foreach my $session ( reverse @sessions ) {
$kernel->_data_ses_stop( $session );
}
(@roots is the list of sessions to stop).
This does a fairly good job of cleaning up stuck grandchildren. For instance, when
POE::Component::Server::JSONRPC crashes due to e.g. an uncought exception, and needs to
be restarted, its nested POE::Component::Server::TCP session needs to be cleaned up to free
the socket as well. This code does the trick.