From: Tyler Riddle Date: Tue, 6 Nov 2012 23:23:17 +0000 (-0800) Subject: alarm() in fatnode is now set to value of connection timeout and is always used even... X-Git-Tag: v0.003001_01~90 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=8faf2a289aa3409e7cafe2536f943fb43033b086 alarm() in fatnode is now set to value of connection timeout and is always used even with out the watchdog enabled --- diff --git a/lib/Object/Remote/Node.pm b/lib/Object/Remote/Node.pm index 93ca232..a790ba8 100644 --- a/lib/Object/Remote/Node.pm +++ b/lib/Object/Remote/Node.pm @@ -10,11 +10,7 @@ use CPS::Future; sub run { my ($class, %args) = @_; log_trace { "run() has been invoked on remote node" }; - - if ($args{watchdog_timeout}) { - Object::Remote::WatchDog->new(timeout => $args{watchdog_timeout}); - } - + my $c = Object::Remote::Connector::STDIO->new->connect; $c->register_class_call_handler; @@ -30,6 +26,12 @@ sub run { print { $c->send_to_fh } "Shere\n"; log_debug { "Node is going to start the run loop" }; + if ($args{watchdog_timeout}) { + Object::Remote::WatchDog->new(timeout => $args{watchdog_timeout}); + } else { + #reset connection watchdog from the fatnode + alarm(0); + } $loop->want_run; $loop->run_while_wanted; log_debug { "Run loop invocation in node has completed" }; diff --git a/lib/Object/Remote/Role/Connector.pm b/lib/Object/Remote/Role/Connector.pm index d3b43c5..a4bce2e 100644 --- a/lib/Object/Remote/Role/Connector.pm +++ b/lib/Object/Remote/Role/Connector.pm @@ -7,7 +7,7 @@ use Moo::Role; requires '_open2_for'; -has timeout => (is => 'ro', default => sub { { after => 10 } }); +has timeout => (is => 'ro', default => sub { 10 }); sub connect { my $self = shift; @@ -43,7 +43,7 @@ sub connect { log_trace { "initialized events on channel for child pid '$child_pid'; creating timeout" }; Object::Remote->current_loop ->watch_time( - %{$self->timeout}, + after => $self->timeout, code => sub { Dlog_trace { "Connection timeout timer has fired for child pid '$child_pid'; is_ready: $_" } $f->is_ready; unless($f->is_ready) { diff --git a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm index a7b4316..79f2660 100644 --- a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm +++ b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm @@ -186,15 +186,20 @@ sub _setup_watchdog_reset { sub fatnode_text { my ($self) = @_; + my $connection_timeout = $self->timeout; + my $watchdog_timeout = $self->watchdog_timeout; my $text = ''; require Object::Remote::FatNode; - if (defined($self->watchdog_timeout)) { - $text = "my \$WATCHDOG_TIMEOUT = '" . $self->watchdog_timeout . "';\n"; - $text .= "alarm(\$WATCHDOG_TIMEOUT);\n"; + if (defined($connection_timeout)) { + $text .= "alarm($connection_timeout);\n"; + } + + if (defined($watchdog_timeout)) { + $text .= "my \$WATCHDOG_TIMEOUT = $watchdog_timeout;\n"; } else { - $text = "my \$WATCHDOG_TIMEOUT = undef;\n"; + $text .= "my \$WATCHDOG_TIMEOUT = undef;\n"; } $text .= <<'END'; diff --git a/t/watchdog_fatnode.t b/t/watchdog_fatnode.t index 81e8c96..ee954f0 100644 --- a/t/watchdog_fatnode.t +++ b/t/watchdog_fatnode.t @@ -9,7 +9,7 @@ $SIG{ALRM} = sub { die "alarm signal\n" }; open(my $nullfh, '>', '/dev/null') or die "Could not open /dev/null: $!"; -my $fatnode_text = Object::Remote::Connector::Local->new(watchdog_timeout => 1)->fatnode_text; +my $fatnode_text = Object::Remote::Connector::Local->new(timeout => 1)->fatnode_text; #this simulates a node that has hung before it reaches #the watchdog initialization - it's an edge case that