From: Tyler Riddle Date: Fri, 30 Nov 2012 01:36:37 +0000 (-0800) Subject: proxy dies() when a method is invoked and the handle is not valid; add 2 more exclusi... X-Git-Tag: v0.003001_01~57 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=5add5e29851e82862e4d8f6d67dfce559f6685ce proxy dies() when a method is invoked and the handle is not valid; add 2 more exclusions to log forwarding --- diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index e47b8fc..4120395 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -16,6 +16,7 @@ use Module::Runtime qw(use_module); use Scalar::Util qw(weaken blessed refaddr openhandle); use JSON::PP qw(encode_json); use Moo; +use Carp qw(croak); BEGIN { router()->exclude_forwarding; @@ -343,7 +344,7 @@ sub _send { my $fh = $self->send_to_fh; unless ($self->is_valid) { - die "Attempt to invoke _send on a connection that is not valid"; + croak "Attempt to invoke _send on a connection that is not valid"; } Dlog_trace { "Starting to serialize data in argument to _send for connection $_" } $self->_id; diff --git a/lib/Object/Remote/Handle.pm b/lib/Object/Remote/Handle.pm index 8b1bd31..7e9c218 100644 --- a/lib/Object/Remote/Handle.pm +++ b/lib/Object/Remote/Handle.pm @@ -14,7 +14,7 @@ use Moo; BEGIN { router()->exclude_forwarding } has connection => ( - is => 'ro', required => 1, + is => 'ro', required => 1, handles => ['is_valid'], coerce => sub { blessed($_[0]) ? $_[0] @@ -58,11 +58,14 @@ sub BUILD { sub call { my ($self, $method, @args) = @_; my $w = wantarray; - log_trace { my $def = defined $w ? 1 : 0; "call() has been invoked on a remote handle; wantarray: '$def'" }; + my $id = $self->id; $method = "start::${method}" if (caller(0)||'') eq 'start'; + log_trace { "call('$method') has been invoked on remote handle '$id'; creating future" }; + future { - $self->connection->send(call => $self->id, $w, $method, @args) + log_debug { "Invoking send on connection for handle '$id' method $method" }; + $self->connection->send(call => $id, $w, $method, @args) }; } diff --git a/lib/Object/Remote/Proxy.pm b/lib/Object/Remote/Proxy.pm index 3c46eeb..68706bd 100644 --- a/lib/Object/Remote/Proxy.pm +++ b/lib/Object/Remote/Proxy.pm @@ -1,6 +1,7 @@ package Object::Remote::Proxy; use strictures 1; +use Carp qw(croak); sub AUTOLOAD { my $self = shift; @@ -9,6 +10,11 @@ sub AUTOLOAD { if ((caller(0)||'') eq 'start') { $to_fire = "start::${to_fire}"; } + + unless ($self->{remote}->is_valid) { + croak "Attempt to use Object::Remote::Proxy backed by an invalid handle"; + } + $self->{remote}->$to_fire($method => @_); } diff --git a/lib/Object/Remote/Role/Connector.pm b/lib/Object/Remote/Role/Connector.pm index 747341c..d294517 100644 --- a/lib/Object/Remote/Role/Connector.pm +++ b/lib/Object/Remote/Role/Connector.pm @@ -2,13 +2,15 @@ package Object::Remote::Role::Connector; use Module::Runtime qw(use_module); use Object::Remote::Future; -use Object::Remote::Logging qw(:log :dlog ); +use Object::Remote::Logging qw(:log :dlog router); use Moo::Role; requires '_open2_for'; has timeout => (is => 'ro', default => sub { 10 }); +BEGIN { router()->exclude_forwarding; } + sub connect { my $self = shift; Dlog_debug { "Preparing to create connection with args of: $_" } @_; diff --git a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm index 16bf6a6..0a7ad67 100644 --- a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm +++ b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm @@ -4,7 +4,7 @@ use IPC::Open2; use IPC::Open3; use IO::Handle; use Symbol; -use Object::Remote::Logging qw( :log :dlog router ); +use Object::Remote::Logging qw(:log :dlog router); use Object::Remote::ModuleSender; use Object::Remote::Handle; use Object::Remote::Future; @@ -25,6 +25,8 @@ has connection_id => (is => 'rwp'); #of the child will be connected to stderr of the parent has stderr => ( is => 'rw', default => sub { undef } ); +BEGIN { router()->exclude_forwarding; } + sub _build_module_sender { my ($hook) = grep {blessed($_) && $_->isa('Object::Remote::ModuleLoader::Hook') } diff --git a/lib/Object/Remote/Role/LogForwarder.pm b/lib/Object/Remote/Role/LogForwarder.pm index 1ff8e5f..cad2572 100644 --- a/lib/Object/Remote/Role/LogForwarder.pm +++ b/lib/Object/Remote/Role/LogForwarder.pm @@ -23,7 +23,11 @@ after _deliver_message => sub { local $reentrant = $package; - $destination->_deliver_message($level, $generator, $args, $metadata); + eval { $destination->_deliver_message($level, $generator, $args, $metadata) }; + + if ($@ && $@ !~ /^Attempt to use Object::Remote::Proxy backed by an invalid handle/) { + die $@; + } }; sub exclude_forwarding { diff --git a/lib/Object/Remote/WatchDog.pm b/lib/Object/Remote/WatchDog.pm index 3d47ac4..7e4d1fe 100644 --- a/lib/Object/Remote/WatchDog.pm +++ b/lib/Object/Remote/WatchDog.pm @@ -1,18 +1,20 @@ package Object::Remote::WatchDog; use Object::Remote::MiniLoop; -use Object::Remote::Logging qw ( :log :dlog ); +use Object::Remote::Logging qw (:log :dlog router); use Moo; has timeout => ( is => 'ro', required => 1 ); +BEGIN { router()->exclude_forwarding; } + around new => sub { my ($orig, $self, @args) = @_; our ($WATCHDOG); return $WATCHDOG if defined $WATCHDOG; log_trace { "Constructing new instance of global watchdog" }; - return $WATCHDOG = $self->$orig(@args); + return $WATCHDOG = $self->$orig(@args); }; #start the watchdog