Subject: | infinite loop on read from closed connection |
Date: | Fri, 11 Mar 2011 11:36:35 +1100 |
To: | bug-X11-Protocol [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
In recent debian X11::Protocol 0.56 and perl 5.10.1 if the server has
closed the X connection then an attempt to read a reply or event from it
goes into an apparently infinite loop using 100% cpu.
The program foo.pl uses KillClient to ask the server to close the
connection. It hangs at
QueryPointer ...
without going on to the "done".
In FileHandle.pm and Socket.pm I think sysread() returns $n==0 for EOF
from the server
Doing the KillClient in the same client program might be a bit of a race
condition, but at any rate reading after someone (anyone) has
KillClient'ed the connection is the problem.
use strict;
use X11::Protocol;
print "DISPLAY $ENV{DISPLAY}\n";
my $X = X11::Protocol->new;
my $pixmap = $X->new_rsrc;
$X->CreatePixmap ($pixmap,
$X->{'root'},
$X->{'root_depth'},
1,1); # width,height
$X->KillClient($pixmap);
print "QueryPointer ...\n";
$X->QueryPointer($X->{'root'});
print "... done\n";
exit 0;
--- FileHandle.pm.orig 2011-02-28 17:57:40.000000000 +1100
+++ FileHandle.pm 2011-02-28 18:26:48.000000000 +1100
@@ -31,6 +31,7 @@
until ($o == $len) {
$n = sysread $fh, $x, $len - $o, $o;
croak $! unless defined $n;
+ croak "Connection closed" unless $n; # $n==0 EOF at server close
$o += $n;
}
return $x;
--- Socket.pm.orig 2011-02-28 17:58:03.000000000 +1100
+++ Socket.pm 2011-02-28 18:26:49.000000000 +1100
@@ -31,6 +31,7 @@
until ($o == $len) {
$n = $sock->sysread($x, $len - $o, $o);
croak $! unless defined $n;
+ croak "Connection closed" unless $n; # $n==0 EOF at server close
$o += $n;
}
return $x;