State corruption in AnyEvent::Loop

Felipe Gasper felipe at felipegasper.com
Sat Jun 27 13:08:57 CEST 2020


Have you dug into AE’s Perl loop to see if there’s a potential fix there? Looks like maybe something setting $_ that could use a lexical instead?

The interpreter has changed some of the edge-case semantics of $_ in recent years; that may be why the breakage only manifests in newer versions.

-F

> On Jun 27, 2020, at 06:20, Yorhel <info at yorhel.nl> wrote:
> 
> Hi,
> 
> Please consider this as a heads up rather than a bug report, because I
> strongly suspect that this is a bug in perl rather than in AnyEvent.
> 
> What I've observed is that it is possible to corrupt the internal state
> of AnyEvent's pure-perl event model by breaking out of a while loop over
> a filehandle, i.e. `while(<$FH>) { last }` is enough to cause havoc.
> 
> I've attached a minimal script with which I can reproduce the problem on
> perl 5.30.3 x86_64-linux with AnyEvent 7.17. The problem does not occur
> when the EV model is used. I suspect the problem also does not occur on
> earlier perl versions, seeing as someone else has gotten the exact same
> error message almost 3 years ago:
> 
> https://stackoverflow.com/questions/45622484/does-anyevent-work-with-perl-5-26
> 
> (Why was that even reported on Stack Overflow rather than the proper
> channels? sigh...)
> 
> The test script has two useful-but-commented-out 'warn' lines,
> uncommenting them (and patching AnyEvent::Loop to expose @fds) clearly
> shows that the 'while' line is modifying internal state of AnyEvent.
> I've included the output that gave on my machine.
> 
> I'm a bit at a loss here. I'll try to report this at perl upstream
> if/when I manage to create a minimal example that exposes the bug
> without AnyEvent. Until then, using the EV model or writing the
> following instead will do as workaround:
> 
>  while(local $_ = <$FH>) {..}
> 
> I'm curious to hear if anyone else has seen similar issues or can
> provide more insight into this behavior.
> 
> Thanks,
> 
> Yorhel.
> <event-loop-corruption.pl>
> <event-loop-corruption.out>
> _______________________________________________
> anyevent mailing list
> anyevent at lists.schmorp.de
> http://lists.schmorp.de/mailman/listinfo/anyevent




More information about the anyevent mailing list