I feel like I'm debugging quantum entanglement in my code. A string I'm reading from a file in one part of the code ended up in the *internal state* of the event loop.
...that's not supposed to happen.
Initial investigation & report: http://lists.schmorp.de/pipermail/anyevent/2020q2/000912.html
Turns out that AnyEvent was leaking a reference to its internal state through $_ and my attempt to read a line from a file would overwrite that variable instead of creating a newly scoped $_.
Global variables, not even once.
@ayo but event loops work by intercepting all IO, right?
@wolf480pl They (at least the one I'm using) poll for readyness on file descriptors, they don't read/write any data directly.
It's worse, the file I'm reading the string from isn't even registered with the event loop, this is just blocking I/O.
@ayo in what language is the code written?
@wolf480pl A supposedly memory-safe one (Perl).
@ayo sounds like severe mushrooms. No idea what happened there. Good luck.
why would a while use global variable by default?
Why would $_ ever be not lexically scoped?
@wolf480pl I don't know the file details, this is pre-5.8 stuff, but I'm guessing it went something like this: Historically, $_ was a global variable (still is, I think. Perl is built on globals...), then at some point it was made possible to temporarily overwrite a global variable within a certain scope, functions called from that scope would also observe that change but functions outside wouldn't (this is what 'local' does, real handy feature).
Why does a while loop not localize $_? Not sure, I'm guessing its so that you can still access the value from the last iteration, maybe a backwards compat thing. for/foreach loops do localize $_.
A lonely little town in the wider world of the fediverse.