Skip Menu |
 

This queue is for tickets about the Net-Server CPAN distribution.

Report information
The Basics
Id: 111356
Status: open
Priority: 0/
Queue: Net-Server

People
Owner: Nobody in particular
Requestors: rjbs [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Attachments
0001-add-register_child-the-inverse-of-delete_child.patch



Subject: add a method to be called immediately when child forks
Download (untitled) / with headers
text/plain 706b
I am volunteering to write this patch if it is approved. In PreForkSimple (for example) this happens: for (1 .. $n) { $self->pre_fork_hook; local $!; my $pid = fork; $self->fatal("Bad fork [$!]") if ! defined $pid; if ($pid) { $prop->{'children'}->{$pid}->{'status'} = 'processing'; } else { $self->run_child; } } I want to add a line inside the "if ($pid)" branch so that I can register children in the parent. Later, delete_child can take action based on the child registered there. I think this will be quite useful in doing extra accounting. Please let me know whether this is acceptable. Thanks, -- rjbs
Subject: Re: [rt.cpan.org #111356] add a method to be called immediately when child forks
Date: Sun, 24 Jan 2016 08:31:47 -0700
To: bug-Net-Server [...] rt.cpan.org
From: Paul Seamons <paul [...] seamons.com>
Download (untitled) / with headers
text/plain 1.4k
Yes. This is a wonderful idea. I can write that in or you are welcome to send a patch. I'll see if I can get a release out with the other issues that have accumulated too. On Jan 21, 2016 2:33 PM, Ricardo Signes via RT <bug-Net-Server@rt.cpan.org> wrote: Show quoted text
> > Thu Jan 21 16:33:26 2016: Request 111356 was acted upon. > Transaction: Ticket created by RJBS >        Queue: Net-Server >      Subject: add a method to be called immediately when child forks >    Broken in: (no value) >     Severity: (no value) >        Owner: Nobody >   Requestors: rjbs@cpan.org >       Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=111356 > > > > I am volunteering to write this patch if it is approved. > > In PreForkSimple (for example) this happens: > >     for (1 .. $n) { >         $self->pre_fork_hook; >         local $!; >         my $pid = fork; >         $self->fatal("Bad fork [$!]") if ! defined $pid; > >         if ($pid) { >             $prop->{'children'}->{$pid}->{'status'} = 'processing'; >         } else { >             $self->run_child; >         } >     } > > I want to add a line inside the "if ($pid)" branch so that I can register children in the parent.  Later, delete_child can take action based on the child registered there.  I think this will be quite useful in doing extra accounting.  Please let me know whether this is acceptable. > > Thanks, > > -- > rjbs
Download (untitled) / with headers
text/plain 213b
I meet you halfway with a patch that seems perfectly correct but has not been carefully tested. :-) I named the callback register_child, in reference to delete_child, but had also considered fork_hook. -- rjbs
Subject: 0001-add-register_child-the-inverse-of-delete_child.patch
From 47a7d077847ef993ad609147b39a46250cab40c2 Mon Sep 17 00:00:00 2001 From: Ricardo Signes <rjbs@cpan.org> Date: Thu, 28 Jan 2016 18:56:12 -0500 Subject: [PATCH] add register_child, the inverse of delete_child --- lib/Net/Server.pm | 2 ++ lib/Net/Server/Fork.pm | 2 ++ lib/Net/Server/PreFork.pm | 1 + lib/Net/Server/PreForkSimple.pm | 1 + 4 files changed, 6 insertions(+) diff --git a/lib/Net/Server.pm b/lib/Net/Server.pm index 59fb44e..3be6eb2 100644 --- a/lib/Net/Server.pm +++ b/lib/Net/Server.pm @@ -671,6 +671,7 @@ sub done { } sub pre_fork_hook {} +sub register_child {} sub child_init_hook {} sub child_finish_hook {} @@ -691,6 +692,7 @@ sub run_dequeue { # fork off a child process to handle dequeuing exit; } $self->log(4, "Running dequeue child $pid"); + $self->register_child($pid); $self->{'server'}->{'children'}->{$pid}->{'status'} = 'dequeue' if $self->{'server'}->{'children'}; diff --git a/lib/Net/Server/Fork.pm b/lib/Net/Server/Fork.pm index 668d400..fbb1b36 100644 --- a/lib/Net/Server/Fork.pm +++ b/lib/Net/Server/Fork.pm @@ -145,6 +145,8 @@ sub loop { exit; } + $self->register_child($pid); + # parent close($prop->{'client'}) if !$prop->{'udp_true'}; $prop->{'children'}->{$pid}->{'status'} = 'processing'; diff --git a/lib/Net/Server/PreFork.pm b/lib/Net/Server/PreFork.pm index d986f1a..e24276c 100644 --- a/lib/Net/Server/PreFork.pm +++ b/lib/Net/Server/PreFork.pm @@ -177,6 +177,7 @@ sub run_n_children { $prop->{'children'}->{$pid}->{'sock'} = $parentsock; } + $self->register_child($pid); $prop->{'children'}->{$pid}->{'status'} = 'waiting'; $prop->{'tally'}->{'waiting'} ++; diff --git a/lib/Net/Server/PreForkSimple.pm b/lib/Net/Server/PreForkSimple.pm index fcccb74..082b54e 100644 --- a/lib/Net/Server/PreForkSimple.pm +++ b/lib/Net/Server/PreForkSimple.pm @@ -145,6 +145,7 @@ sub run_n_children { $self->fatal("Bad fork [$!]") if ! defined $pid; if ($pid) { + $self->register_child($pid); $prop->{'children'}->{$pid}->{'status'} = 'processing'; } else { $self->run_child; -- 2.6.2
Download (untitled) / with headers
text/plain 142b
Anything I can do to help this along? Getting close to monkeypatching these methods in our internal use, which I'd rather avoid! :) -- rjbs
Subject: Re: [rt.cpan.org #111356] add a method to be called immediately when child forks
Date: Mon, 28 Mar 2016 22:08:27 -0600
To: bug-Net-Server [...] rt.cpan.org
From: Paul Seamons <paul [...] seamons.com>
Download (untitled) / with headers
text/plain 413b
Sorry. I will try tomorrow. We've had this in our sprint but have repeatedly gotten superceded. I'll get it in. Paul On 03/24/2016 05:43 PM, Ricardo Signes via RT wrote: Show quoted text
> Queue: Net-Server > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=111356 > > > Anything I can do to help this along? Getting close to monkeypatching these methods in our internal use, which I'd rather avoid! :) >
I'm going to go ahead and fork this internally for now. -- rjbs
Download (untitled) / with headers
text/plain 186b
I thought I'd share the code that I wrote on top of this patch: https://github.com/rjbs/Net-Server-Tracker I look forward to putting it into all of our servers this week! :-) -- rjbs


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.