Added prevent-hang patch (2880462) submitted by Panos

git-svn-id: svn+ssh://svn.code.sf.net/p/ddclient/code/trunk@114 3873ddee-7413-0410-b6c4-c2c57c1ab35a
This commit is contained in:
wimpunk 2009-11-09 20:25:58 +00:00
parent 7f7c7ac15b
commit 8fff829fa2
2 changed files with 67 additions and 30 deletions

View file

@ -1838,39 +1838,39 @@ sub geturl {
defined $sd or warning("cannot connect to $peer:$port socket: $@"); defined $sd or warning("cannot connect to $peer:$port socket: $@");
} }
if (defined $sd) { if (defined $sd) {
## send the request to the http server ## send the request to the http server
verbose("CONNECTED: ", $use_ssl ? 'using SSL' : 'using HTTP'); verbose("CONNECTED: ", $use_ssl ? 'using SSL' : 'using HTTP');
verbose("SENDING:", $request); verbose("SENDING:", $request);
$0 = sprintf("%s - sending to %s port %s", $program, $peer, $port); $0 = sprintf("%s - sending to %s port %s", $program, $peer, $port);
my $result = syswrite $sd, $rq; my $result = syswrite $sd, $rq;
if ($result != length($rq)) { if ($result != length($rq)) {
warning("cannot send to $peer:$port ($!)."); warning("cannot send to $peer:$port ($!).");
} else {
} else { $0 = sprintf("%s - reading from %s port %s", $program, $peer, $port);
my $timeout = 0; eval {
local $SIG{'ALRM'} = sub { $timeout = 1; }; local $SIG{'ALRM'} = sub { die "timeout";};
alarm(opt('timeout')) if opt('timeout') > 0;
while ($_ = <$sd>) {
$0 = sprintf("%s - read from %s port %s", $program, $peer, $port);
verbose("RECEIVE:", "%s", define($_, "<undefined>"));
$reply .= $_ if defined $_;
}
if (opt('timeout') > 0) {
alarm(0);
}
};
close($sd);
$0 = sprintf("%s - reading from %s port %s", $program, $peer, $port); if ($@ and $@ =~ /timeout/) {
alarm(opt('timeout')) if opt('timeout') > 0; warning("TIMEOUT: %s after %s seconds", $to, opt('timeout'));
while (!$timeout && ($_ = <$sd>)) { $reply = '';
$0 = sprintf("%s - read from %s port %s", $program, $peer, $port); }
verbose("RECEIVE:", "%s", define($_, "<undefined>")); $reply = '' if !defined $reply;
$reply .= $_ if defined $_; }
}
if (opt('timeout') > 0) {
alarm(0);
}
close($sd);
if ($timeout) {
warning("TIMEOUT: %s after %s seconds", $to, opt('timeout'));
$reply = '';
}
$reply = '' if !defined $reply;
} }
} $0 = sprintf("%s - closed %s port %s", $program, $peer, $port);
$0 = sprintf("%s - closed %s port %s", $program, $peer, $port);
## during testing simulate reading the URL ## during testing simulate reading the URL
if (opt('test')) { if (opt('test')) {

View file

@ -0,0 +1,37 @@
# http://sourceforge.net/tracker/?func=detail&atid=676130&aid=2880462&group_id=116817
# ddclient hangs forever under some circumstances - ID: 2880462
#
Index: ddclient
===================================================================
--- ddclient (revision 113)
+++ ddclient (working copy)
@@ -1847,14 +1847,12 @@
my $result = syswrite $sd, $rq;
if ($result != length($rq)) {
warning("cannot send to $peer:$port ($!).");
-
} else {
- my $timeout = 0;
- local $SIG{'ALRM'} = sub { $timeout = 1; };
-
$0 = sprintf("%s - reading from %s port %s", $program, $peer, $port);
+ eval {
+ local $SIG{'ALRM'} = sub { die "timeout";};
alarm(opt('timeout')) if opt('timeout') > 0;
- while (!$timeout && ($_ = <$sd>)) {
+ while ($_ = <$sd>) {
$0 = sprintf("%s - read from %s port %s", $program, $peer, $port);
verbose("RECEIVE:", "%s", define($_, "<undefined>"));
$reply .= $_ if defined $_;
@@ -1862,8 +1860,10 @@
if (opt('timeout') > 0) {
alarm(0);
}
+ };
close($sd);
- if ($timeout) {
+
+ if ($@ and $@ =~ /timeout/) {
warning("TIMEOUT: %s after %s seconds", $to, opt('timeout'));
$reply = '';
}