Subject: | Connections occasionally time out and cause errors |
Date: | Sat, 19 Sep 2020 23:27:01 -0400 |
To: | bug-Net-Telnet [...] rt.cpan.org |
From: | Asher Gordon <AsDaGo [...] posteo.net> |
Hello,
I found this bug in Net::Telnet 3.04, but the supplied patch is patched
against 3.04_01 (although it also applies against 3.04).
I used Net::Telnet to write a chat bot for the Free Internet Chess
Server (freechess.org), called blikII. However, sometimes it seems to
timeout, but Net::Telnet does not recognize it as a timeout, and thus
does not flag it as such. I believe that the attached patch should fix
the problem, but I haven't tested it much.
Here is the output of 'perl -v':
This is perl 5, version 30, subversion 3 (v5.30.3) built for x86_64-linux-gnu-thread-multi
(with 50 registered patches, see perl -V for more detail)
Copyright 1987-2020, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
And my operating system version is Debian GNU/Linux 11 "Bullseye". The
output of 'uname -a' is as follows:
Linux Xanthus 5.8.0-1-amd64 #1 SMP Debian 5.8.7-1 (2020-09-05) x86_64 GNU/Linux
Also, I believe the error message was "read error: Connection timed out
at <...>" (since errno ($!) was ETIMEDOUT).
Here is the patch which (I believe) fixes the problem:
diff -pur Net-Telnet-3.04_01.orig/lib/Net/Telnet.pm Net-Telnet-3.04_01/lib/Net/Telnet.pm
--- Net-Telnet-3.04_01.orig/lib/Net/Telnet.pm 2020-02-17 08:12:07.000000000 -0500
+++ Net-Telnet-3.04_01/lib/Net/Telnet.pm 2020-09-19 23:02:58.031015494 -0400
@@ -43,6 +43,7 @@ my $AF_UNSPEC = &_import_af_unspec() ||
my $AI_ADDRCONFIG = &_import_ai_addrconfig() || 0;
my $EAI_BADFLAGS = &_import_eai_badflags() || -1;
my $EINTR = &_import_eintr();
+my $ETIMEDOUT = &_import_etimedout();
## Global variables.
use vars qw($VERSION @Telopts);
@@ -2602,6 +2603,12 @@ sub _fillbuf {
else {
next if $! =~ /^interrupted/i; # restart select()
}
+ if (defined $ETIMEDOUT) {
+ next if $! == $ETIMEDOUT; # restart select()
+ }
+ else {
+ next if $! =~ /timed out/i; # restart select()
+ }
$s->{opened} = '';
return $self->error("read error: $!");
@@ -2628,6 +2635,12 @@ sub _fillbuf {
else {
next if $! =~ /^interrupted/i; # restart sysread()
}
+ if (defined $ETIMEDOUT) {
+ next if $! == $ETIMEDOUT; # restart sysread()
+ }
+ else {
+ next if $! =~ /timed out/i; # restart sysread()
+ }
$s->{opened} = '';
return $self->error("read error: $!");
@@ -2778,6 +2791,14 @@ sub _import_eintr {
} # end sub _import_eintr
+sub _import_etimedout {
+ local $@;
+ local $SIG{"__DIE__"} = "DEFAULT";
+
+ eval "require Errno; Errno::ETIMEDOUT();";
+} # end sub _import_etimedout
+
+
sub _interpret_cr {
my ($s, $pos) = @_;
my (
@@ -3645,6 +3666,12 @@ sub _put {
else {
next if $! =~ /^interrupted/i; # restart select()
}
+ if (defined $ETIMEDOUT) {
+ next if $! == $ETIMEDOUT; # restart select()
+ }
+ else {
+ next if $! =~ /timed out/i; # restart select()
+ }
$s->{opened} = '';
return $self->error("write error: $!");
@@ -3662,6 +3689,12 @@ sub _put {
else {
next if $! =~ /^interrupted/i; # restart syswrite()
}
+ if (defined $ETIMEDOUT) {
+ next if $! == $ETIMEDOUT; # restart syswrite()
+ }
+ else {
+ next if $! =~ /timed out/i; # restart syswrite()
+ }
$s->{opened} = '';
return $self->error("write error: $!");
Thanks,
Asher
--
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me sprea=
d!
--------
I prefer to send and receive mail encrypted. Please send me your
public key, and if you do not have my public key, please let me
know. Thanks.
GPG fingerprint: 38F3 975C D173 4037 B397 8095 D4C9 C4FC 5460 8E68
Message body not shown because it is not plain text.