Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Forking within AnyEvent::Socket::tcp_server? [SOLVED]

by Riales (Hermit)
on Sep 23, 2013 at 21:36 UTC ( #1055388=perlquestion: print w/replies, xml ) Need Help??
Riales has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I'm trying to write a forking server using AnyEvent::Socket::tcp_server, but am running into an issue with the forking. Here is what I am trying to do right now:

use AnyEvent::Socket; use AnyEvent::Handle; use Parallel::ForkManager; # Some omitted initialization stuffs my $forker = Parallel::ForkManager->new(10); AnyEvent::Socket::tcp_server(undef, $port, sub { my ($fh, $host, $port) = @_; $forker->start and return; my $handle = AnyEvent::Handle->new( fh => $fh, keepalive => 1, on_connect => $on_connect_sub, on_read => $on_read_sub, on_error => $on_error_sub, ); }, ); AnyEvent->condvar->wait();

This is the error I get sometimes (but not always) while connecting:

Cannot start another process while you are in the child process at /us +r/local/share/perl/5.14.2/Parallel/ForkManager.pm line 476.

If I comment out the line that does the forking, the server seems to run fine (it just doesn't fork). Does anybody know what I am doing wrong with the forking?

------------------------------

EDIT: Figured it out after some thought. I'm still a bit hazy on the details so I'm not sure I can vocalize it all properly, BUT here's what I think was happening:

When the code accepted a connection, I would fork and the child would create a handler. While it was great that the handler was in the child thread, I think the child could also still accept connections. I'm not sure how this part was arbitrated, but sometimes, an incoming connection would be accepted by the child, but because the child could not fork, both the original connection and the incoming connection would fail due to the failed fork.

Hope that makes sense. Hopefully somebody more knowledgable will come along and shed more light on the situation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1055388]
Approved by marinersk
help
Chatterbox?
[Corion]: perldigious: That seems to be more the export and likely it's the recipients of that export that like the titles changes
[Corion]: ... "changed"
[Corion]: I usually expect fixed header names, but am sometimes lenient in the order of columns. But changing the report titles often sounds to me as if you are not the sole consument of the export ;)
[shmem]: perldigious: as always - if it ain't broke, don't fix it. Ther must be a very compelling reason for changing column names in a database. Those are rare.
[Corion]: If you have whitespace in the column names in the database, whap the DBAs ;)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-05-25 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?