You have to remove all events for the session to gc. Just add the line below and it will work like you want if I read enough of your code to grasp it.
> sub child_error {
> my ($function, $error) = @_[ARG0, ARG2];
--> $_[KERNEL]->alarm_remove_all();
> delete $_[HEAP]->{readwrite};
> print "CHILD: call to $function() failed: $error.\n" if $error;
> }
