New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing file handles early breaks IO::Select #10388
Comments
From bre@klaki.netCreated by bre@klaki.net(re-posting what I sent to perl5-porters: the IO::Select perldoc I write to you, because I think I have found and fixed a rather The bug is: IO::Select currently assumes that an IO::Handle will Attached is a sample program which triggers the bug, and a proposed http://bre.klaki.net/programs/Perl-IO-Select-Bug/ Addition: The real-world impact of this bug, is to cause most servers written Perl Info
|
From @jkeenanOn Tue May 18 00:35:01 2010, bre@klaki.net wrote:
This older ticket is difficult to evaluate because the attachments the Nevertheless, I can't reproduce the poster's complaint about IO::Select, Thank you very much. |
From @jkeenan#!/usr/bin/perl # First just create a couple of sockets to play with. # Add them to our select objects... # Make $dumb_client->fileno return undef. # Trigger and test the bug: we cannot remove $dumb_client ! |
From @jkeenan |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Tue May 18 00:35:01 2010, bre@klaki.net wrote:
I’ve fixed that with commit 9f7d1e4. -- Father Chrysostomos |
From @tonycozOn Tue Jan 03 19:06:13 2012, jkeenan wrote:
There's a partial fix for this issue in 2e6546c, unfortunately that fix - it doesn't update the bit vector ($bits) so the next can_read() will - it doesn't update $count, so remove returns failure even though the FH Tony |
From @tonycozOn Tue Sep 17 19:11:58 2013, tonyc wrote:
Tests and fixes attached, which I'll apply in a couple of days or so. Tony |
From @tonycoz0002-perl-75156-fix-the-return-value-and-bits-for-removin.patchFrom b58d6c0df55563f960c7413cd97662e2c38870dc Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 18 Sep 2013 15:55:12 +1000
Subject: [PATCH 2/2] [perl #75156] fix the return value and bits for removing
a closed fh
---
dist/IO/lib/IO/Select.pm | 27 ++++++++++++++++++---------
dist/IO/t/io_sel.t | 4 ++--
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/dist/IO/lib/IO/Select.pm b/dist/IO/lib/IO/Select.pm
index 756a299..994f896 100644
--- a/dist/IO/lib/IO/Select.pm
+++ b/dist/IO/lib/IO/Select.pm
@@ -11,7 +11,7 @@ use warnings::register;
use vars qw($VERSION @ISA);
require Exporter;
-$VERSION = "1.21";
+$VERSION = "1.22";
@ISA = qw(Exporter); # This is only so we can do version checking
@@ -86,15 +86,24 @@ sub _update
$vec->[$i] = $f;
} else { # remove
if ( ! defined $fn ) { # remove if fileno undef'd
- defined($_) && $_ == $f and do { $vec->[FD_COUNT]--; $_ = undef; }
- for @{$vec}[FIRST_FD .. $#$vec];
- next;
+ $fn = 0;
+ for my $fe (@{$vec}[FIRST_FD .. $#$vec]) {
+ if (defined($fe) && $fe == $f) {
+ $vec->[FD_COUNT]--;
+ $fe = undef;
+ vec($bits, $fn, 1) = 0;
+ last;
+ }
+ ++$fn;
+ }
+ }
+ else {
+ my $i = $fn + FIRST_FD;
+ next unless defined $vec->[$i];
+ $vec->[FD_COUNT]--;
+ vec($bits, $fn, 1) = 0;
+ $vec->[$i] = undef;
}
- my $i = $fn + FIRST_FD;
- next unless defined $vec->[$i];
- $vec->[FD_COUNT]--;
- vec($bits, $fn, 1) = 0;
- $vec->[$i] = undef;
}
$count++;
}
diff --git a/dist/IO/t/io_sel.t b/dist/IO/t/io_sel.t
index bd61b68..34af03a 100644
--- a/dist/IO/t/io_sel.t
+++ b/dist/IO/t/io_sel.t
@@ -143,9 +143,9 @@ print "ok 23\n" ;
print "ok 24 - added socket\n";
close $fh;
print "not " unless $sel->remove($fh) == 1;
- print "ok 25 - removed closed socket # TODO code doesn't update count\n";
+ print "ok 25 - removed closed socket\n";
print "not " unless $sel->count == 1;
print "ok 26 - count() updated\n";
print "not " unless $sel->bits ne $oldbits;
- print "ok 27 - bits() updated # TODO code doesn't update bits\n";
+ print "ok 27 - bits() updated\n";
}
--
1.7.10.4
|
From @tonycoz0001-perl-75156-tests-for-deleting-a-closed-handle-from-I.patchFrom a78df7b89b5bca007c58dac456521d5b61ff8553 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 18 Sep 2013 15:20:19 +1000
Subject: [PATCH 1/2] [perl #75156] tests for deleting a closed handle from
IO::Select
---
dist/IO/t/io_sel.t | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/dist/IO/t/io_sel.t b/dist/IO/t/io_sel.t
index eb4bb90..bd61b68 100644
--- a/dist/IO/t/io_sel.t
+++ b/dist/IO/t/io_sel.t
@@ -3,7 +3,7 @@
select(STDERR); $| = 1;
select(STDOUT); $| = 1;
-print "1..23\n";
+print "1..27\n";
use IO::Select 1.09;
@@ -129,3 +129,23 @@ IO::Select::has_error();
print "not " unless $w == 1 ;
$w = 0 ;
print "ok 23\n" ;
+
+{
+ # perl #75156 - test we can delete a closed handle
+ require IO::Socket::INET;
+ my $fh = IO::Socket::INET->new(
+ Listen => 5,
+ );
+ my $sel = IO::Select->new(\*STDIN);
+ $sel->add($fh);
+ my $oldbits = $sel->bits;
+ print "not " unless $sel->count == 2;
+ print "ok 24 - added socket\n";
+ close $fh;
+ print "not " unless $sel->remove($fh) == 1;
+ print "ok 25 - removed closed socket # TODO code doesn't update count\n";
+ print "not " unless $sel->count == 1;
+ print "ok 26 - count() updated\n";
+ print "not " unless $sel->bits ne $oldbits;
+ print "ok 27 - bits() updated # TODO code doesn't update bits\n";
+}
--
1.7.10.4
|
From @tonycozOn Tue Sep 17 22:56:31 2013, tonyc wrote:
Applied as 3bfb061 and ff4a442. Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#75156 (status was 'resolved')
Searchable as RT75156$
The text was updated successfully, but these errors were encountered: