select() errors and AnyEvent::Loop

Felipe Gasper felipe at felipegasper.com
Wed Jun 30 17:44:25 CEST 2021



> On Jun 8, 2021, at 9:26 AM, Felipe Gasper <felipe at felipegasper.com> wrote:
> 
> 
>> On Jun 8, 2021, at 2:44 AM, Marc Lehmann <schmorp at schmorp.de> wrote:
>> 
>> On Mon, Jun 07, 2021 at 12:57:30PM -0400, Felipe Gasper <felipe at felipegasper.com> wrote:
>>>> 	I’ve noticed that AnyEvent::Loop doesn’t check for select() failures. Is this by design?
>>>> 
>>>> 	In my testing it leads to a tight loop if, e.g., a file descriptor gets closed from underneath (possible w/ buggy XS modules or misuse of POSIX::close()) or if ENOMEM happens.
>>> 
>>> Pursuant to this: what if the following were added?
>> 
>> I'm reluctant to add something that crashes a possibly correctly working
>> program to give a not very useless diagnostic for broken programs.
> 
> On Linux, anyhow, the only failure states for that system call are:
> 
> - EBADF: bad file descriptor in an FD set
> 
> - EINTR: signal caught (this is a legit nonfatal case)
> 
> - EINVAL: error in the parameters
> 
> - ENOMEM: OOM
> 
> When I make EBADF happen directly the program hangs in a tight loop. I assume the same would go for ENOMEM, and EINVAL shouldn’t be possible in Perl.
> 
> How is it possible for a program that gets EBADF, EINVAL, or ENOMEM from select() to be correctly working? Given that the program is likely stuck, the exception would at least prevent that state and give an indicator as to why.

Any thoughts on this, Marc?

Thank you!

cheers,
-Felipe




More information about the anyevent mailing list