Commit 1ee85494 authored by Mike Hibler's avatar Mike Hibler

If stated were a space probe it would have crashed into Mars...

Minor units conversion problem here. IO::Poll() takes seconds as it argument,
not milliseconds as we were doing (by multiplying the arg by 1000 before
calling).

Unfortunately, this is not the Big One (memory corruption) that we have been
chasing for so long. Sigh...
parent fe54d0e3
...@@ -63,7 +63,7 @@ my $last_reload = time; ...@@ -63,7 +63,7 @@ my $last_reload = time;
# For startup and reload: maximum time in the past for which we will schedule # For startup and reload: maximum time in the past for which we will schedule
# a timeout. Anything older is assumed to be ancient history and is ignored. # a timeout. Anything older is assumed to be ancient history and is ignored.
# Note it is a negative value. # Note it is a negative value.
my $maxpasttimeout = -(2 * 24 * 60 * 60); # 2 days my $maxpasttimeout = -(7 * 24 * 60 * 60); # 1 week
# Handling of SECVIOLATIONS, eventually controlled by a sitevar # Handling of SECVIOLATIONS, eventually controlled by a sitevar
my $soft_secviolation = 1; my $soft_secviolation = 1;
...@@ -296,7 +296,7 @@ sub process_event_queue() { ...@@ -296,7 +296,7 @@ sub process_event_queue() {
} else { } else {
#debug("Using blocking event poll - $wait seconds\n"); #debug("Using blocking event poll - $wait seconds\n");
# timeout param is in milliseconds, so multiply # timeout param is in milliseconds, so multiply
PollEvents(1, $wait*1000); PollEvents(1, $wait);
$now = time(); $now = time();
# subtract seconds elapsed from my wait time # subtract seconds elapsed from my wait time
$wait = $finish - $now; $wait = $finish - $now;
...@@ -430,13 +430,7 @@ sub readStates(;@) { ...@@ -430,13 +430,7 @@ sub readStates(;@) {
$nodes{$node_id}{noretry} = 0; $nodes{$node_id}{noretry} = 0;
# Is there a timeout? If so, set it up! # Is there a timeout? If so, set it up!
if (defined($timestamp) && $dbtag eq $nodes{$node_id}{"tag"}) { if (defined($timestamp) && $dbtag eq $nodes{$node_id}{"tag"}) {
my $TO = $timestamp - $now;
if ($TO > $maxpasttimeout) {
setTimeout($mode,$state,$node_id,$timestamp); setTimeout($mode,$state,$node_id,$timestamp);
} else {
debug("Ignoring ancient timeout $TO for ",
"($node_id,$mode,$state)\n");
}
} }
} }
} }
...@@ -1340,24 +1334,39 @@ sub checkDBRedirect($) { ...@@ -1340,24 +1334,39 @@ sub checkDBRedirect($) {
} }
} }
# Check if this state has a timeout, and if so, put it in the queue #
# Check if this state has a timeout, and if so, put it in the queue.
#
# We also check if the timeout expired at some distant time in the
# past. If that is the case, we just ignore that timeout.
#
sub setTimeout( $$$$ ) { sub setTimeout( $$$$ ) {
my ($mode,$state,$node,$now) = @_; my ($mode,$state,$node,$stime) = @_;
if (0) { print "Original: ($mode,$state,$node,$now)\n"; qshow(); }
# Remove any old timeout first
if (0) { print "Original: ($mode,$state,$node,$stime)\n"; qshow(); }
if (defined(qfind($node))) { qdelete($node); delete($timeout_tag{$node}); } if (defined(qfind($node))) { qdelete($node); delete($timeout_tag{$node}); }
if (0) { print "Deleted:\n"; qshow(); } if (0) { print "Deleted:\n"; qshow(); }
if (defined($mode) && defined($state) && if (defined($mode) && defined($state) &&
defined($timeouts{$mode}) && defined($timeouts{$mode}) && defined($timeouts{$mode}{$state})) {
defined($timeouts{$mode}{$state})) {
my $deadline = ${$timeouts{$mode}{$state}}[0]; my $deadline = ${$timeouts{$mode}{$state}}[0];
if (defined($deadline) && if (defined($deadline) && $deadline != $TBNOTIMEOUT) {
$deadline != $TBNOTIMEOUT) { my $TO = $deadline + $stime;
my $TO = $deadline + $now; my $fromnow = $TO - time();
# see if deadline was too far in the past
if ($fromnow > $maxpasttimeout) {
debug("Setting timeout for ($node,$mode,$state) at ". debug("Setting timeout for ($node,$mode,$state) at ".
"$deadline + $now ($TO)\n"); "$deadline + $stime ($TO: $fromnow seconds from now)\n");
qinsert($TO,$node); qinsert($TO, $node);
$timeout_tag{$node} = "$mode:$state"; $timeout_tag{$node} = "$mode:$state";
if (0) { qshow(); } if (0) { qshow(); }
} else {
$fromnow = -$fromnow;
debug("Ignoring ancient timeout ($fromnow seconds ago) for ",
"($node,$mode,$state)\n");
}
} }
} }
if (0) { print "Done:\n"; qshow(); } if (0) { print "Done:\n"; qshow(); }
...@@ -1875,9 +1884,11 @@ sub PollEvents($$) ...@@ -1875,9 +1884,11 @@ sub PollEvents($$)
fatal("Event reader exited prematurely: $foo $status!\n"); fatal("Event reader exited prematurely: $foo $status!\n");
} }
if ($blocking) { if ($blocking) {
$timeout = undef if ($timeout == 0) {
if (!$timeout); $timeout = undef;
} elsif ($timeout*1000 < 0) {
fatal("Event reader timeout too large ($timeout sec)!\n");
}
$pollval = $eventpoll->poll($timeout); $pollval = $eventpoll->poll($timeout);
} }
else { else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment