select() errors and AnyEvent::Loop
Marc Lehmann
schmorp at schmorp.de
Thu Jul 1 21:01:34 CEST 2021
On Thu, Jul 01, 2021 at 12:09:24PM -0400, Felipe Gasper <felipe at felipegasper.com> wrote:
> strace perl -MAnyEvent -e'pipe my $r, my $w; my $fd = fileno $r; close $w; my $cv = AE::cv(); close $r; my $w = AE::io( $fd, "r", $cv ); $cv->recv()'
>
> … but that’s only indefinite if there’s no timer. AE::Loop *could* detect situations whether select() fails and there is no timer. <shrug>
>
> FWIW, EV/epoll stops right away with the above … though it also doesn’t report the EBADF.
AnyEvent can detect this right away with all event loops using strict
mode, which is recommended to be enabled at least for development:
AnyEvent->io: cannot dup() filehandle in mode 'w': Bad file descriptor, at /opt/perl/lib/perl5/AnyEvent.pm line 1585.
EV, in the case of closing the fd later, will also react differently
depending on the backend, and gives no guarantees either. Nor do most
other event loops. In any case, giving the program a chance to recover is
considered a better choice than crashing a potentially working program.
What might be confusing is that AnyEvent isn't meant to be an educational
tool nor a fluffly learning environment, but be as performant as possible
while being correct - supporting debugging or broken programs is not a
(priority) goal.
> > I don't see how "throwing" would make the problem more easily identified.
> > Certainly, "throwing" is unlikely to be correct for _any_ program?
>
> In a “happy-path” scenario, sure, but when errors happen it’s nice IMO to report them rather than discarding them. Yes, it’s the calling program that needs to be fixed, but it’s much easier to do that if the called library helps out.
The called library already helps out in this any many other cases,
and different event implementations can also help out (e.g. libev has
loop->verify). There will always be limits to this, though, and we have to
draw the line somewhere.
In any case, since you are asking to crash potentially working and correct
prorgams for the benefit of incorrect ones, I think this is a bad change
to make, but of course you can patch your version locally, which might be
a good idea since you don't have to support (officially or not) programs
other than your own.
--
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