AnyEvent::Fork::RPC::event not propagating to parent

Marc Lehmann schmorp at schmorp.de
Wed Jan 11 08:37:44 CET 2017


On Mon, Jan 09, 2017 at 09:26:16PM -0700, Art Sackett <asackett at gmx.com> wrote:
> I'm trying to read a 'tail -F /path/to/file' output via piped open in an
> AnyEvent::Fork::RPC::Async child, and send the data back to the parent
> by way of an on_event handler. With no luck; I issue the event by way of
> AnyEvent::Fork::RPC::event but it never reaches the on_event handler of
> the parent.
> 
> To illustrate with minimal code:

Hi, thanks for having such a nice testcase, that made thinsg easier.

Running it with AnyEvent::Strict enabled gives me this after a few
seconds:

   EV: error in callback (ignoring): Modification of a read-only value attempted at (eval 6) line 21.
   EV: error in callback (ignoring): Modification of a read-only value attempted at (eval 6) line 21.
   EV: error in callback (ignoring): Modification of a read-only value attempted ...

The eval is the __DATA__ section, and line 21 is:

                while (<$tail_fh>) {

This modifies $_, a global variable, which can easily confuse AnyEvent or
other code - as a rule of thumb, if you modify special variables (e.g. the
ones from perlvar) they affect all code, so should be localised.

It's not the problem itself here (EV doesn't care about $_), but the
problem is in the same line:

                while (<$tail_fh>) {

This is an endless loop, so you never return. And since your event handle
doesn't return, the event loop won't run, and the event will not be sent.

Replacing it by:

                my $tail_fh = <$tail_fh>; {

Makes the events appear.

Note, however, that the code is still problematic, if tail -f doesn't
output a full line (which it will happily do if the file doesn't end with
a newline) the program will still hang.

One option would be to recognize that the example program doesn't need the
async backend, because it itself isn't "async", it's blocking. Using the
blocking Sync backend would work, because AnyEvent uses a less efficient
transport there that does, however, not rely on any event loop.

Greetings,

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list