|Welcome to the Monastery|
Forking within AnyEvent::Socket::tcp_server? [SOLVED]by Riales (Hermit)
|on Sep 23, 2013 at 21:36 UTC||Need Help??|
Riales has asked for the
wisdom of the Perl Monks concerning the following question:
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:
This is the error I get sometimes (but not always) while connecting:
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.