Subject: | EBADF when removing a handle whose FD is closed |
Date: | Sun, 10 May 2020 08:25:53 -0400 |
To: | bug-IO-Async-Loop-Epoll [...] rt.cpan.org |
From: | Felipe Gasper <felipe [...] felipegasper.com> |
Hello,
The script below will fail if the Epoll class is installed because the underlying epoll_ctl gives EBADF for the already-closed filehandle. It succeeds if you uncomment the line that forces use of Select.pm.
This came up with Net::Curl testing. Perl can’t easily know whether libcurl has close()d the file descriptor, so this is a real-world scenario.
Thank you!
-FG
=====
#!/usr/bin/env perl
use strict;
use warnings;
# $ENV{'IO_ASYNC_LOOP'} = 'Select';
require IO::Async::Loop;
require IO::Async::Handle;
require IO::File;
pipe my $r, my $w;
my $loop = IO::Async::Loop->new();
print "ref: " . ref($loop) . $/;
my $handle = IO::Async::Handle->new(
read_handle => $r,
on_read_ready => sub {},
);
$loop->add($handle);
use POSIX;
POSIX::close( fileno $r );
$loop->remove($handle);
print "done\n";
=====