X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote%2FRole%2FConnector.pm;h=d5d46d76d10a066c8078ec60313e3a3f439758bf;hb=7790ca36241acfa9379cb2b89b68c9f4b0da2371;hp=6da4a9c5331a2f1497f8bea7088c00d8534bb138;hpb=cc670b3044ce1fc9389d9845ee5ea91459f2612e;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote/Role/Connector.pm b/lib/Object/Remote/Role/Connector.pm index 6da4a9c..d5d46d7 100644 --- a/lib/Object/Remote/Role/Connector.pm +++ b/lib/Object/Remote/Role/Connector.pm @@ -2,22 +2,28 @@ package Object::Remote::Role::Connector; use Module::Runtime qw(use_module); use Object::Remote::Future; +use Object::Remote::Logging qw(:log :dlog ); use Moo::Role; requires '_open2_for'; +#TODO return to 10 seconds after debugging +#has timeout => (is => 'ro', default => sub { { after => 10 } }); has timeout => (is => 'ro', default => sub { { after => 10 } }); sub connect { my $self = shift; + Dlog_debug { "Perparing to create connection with args of: $_" } @_; my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_); my $channel = use_module('Object::Remote::ReadChannel')->new( fh => $receive_from_fh ); return future { + log_trace { "Initializing connection for child pid '$child_pid'" }; my $f = shift; $channel->on_line_call(sub { if ($_[0] eq "Shere") { + log_trace { "Received 'Shere' from child pid '$child_pid'; setting done handler to create connection" }; $f->done( use_module('Object::Remote::Connection')->new( send_to_fh => $send_to_fh, @@ -26,6 +32,7 @@ sub connect { ) ); } else { + log_warn { "'Shere' was not found in connection data for child pid '$child_pid'" }; $f->fail("Expected Shere from remote but received: $_[0]"); } undef($channel); @@ -34,14 +41,24 @@ sub connect { $f->fail("Channel closed without seeing Shere: $_[0]"); undef($channel); }); + log_trace { "initialized events on channel for child pid '$child_pid'; creating timeout" }; Object::Remote->current_loop ->watch_time( %{$self->timeout}, code => sub { - $f->fail("Connection timed out") unless $f->is_ready; +# log_warn { "Connection timed out for child pid '$child_pid'" }; +# $f->fail("Connection timed out") unless $f->is_ready; +# undef($channel); + Dlog_trace { "Connection timeout timer has fired for child pid '$child_pid'; is_ready: $_" } $f->is_ready; + unless($f->is_ready) { + log_warn { "Connection with child pid '$child_pid' has timed out" }; + $f->fail("Connection timed out") unless $f->is_ready; + } undef($channel); + } ); + log_trace { "connection for child pid '$child_pid' has been initialized" }; $f; } }