more log lines - found deadlock where controller blocks on read seemingly outside...
[scpubgit/Object-Remote.git] / lib / Object / Remote / Role / Connector / PerlInterpreter.pm
index cfa039a..815ef3e 100644 (file)
@@ -5,6 +5,7 @@ use IO::Handle;
 use Object::Remote::ModuleSender;
 use Object::Remote::Handle;
 use Object::Remote::Future;
+use Object::Remote::Logging qw( :log );
 use Scalar::Util qw(blessed);
 use Moo::Role;
 
@@ -29,6 +30,8 @@ around connect => sub {
   return future {
     $f->on_done(sub {
       my ($conn) = $f->get;
+      my $sub = $conn->remote_sub('Object::Remote::Logging::init_logging_forwarding');
+      $sub->('Object::Remote::Logging', Object::Remote::Logging->arg_router);
       Object::Remote::Handle->new(
         connection => $conn,
         class => 'Object::Remote::ModuleLoader',
@@ -53,10 +56,13 @@ sub _start_perl {
   return ($foreign_stdin, $foreign_stdout, $pid);
 }
 
+#TODO open2() forks off a child and I have not been able to locate
+#a mechanism for reaping dead children so they don't become zombies
 sub _open2_for {
   my $self = shift;
   my ($foreign_stdin, $foreign_stdout, $pid) = $self->_start_perl(@_);
   my $to_send = $self->fatnode_text;
+  log_debug { my $len = length($to_send); "Sending contents of fat node to remote node; size is '$len' characters"  };
   Object::Remote->current_loop
                 ->watch_io(
                     handle => $foreign_stdin,
@@ -68,11 +74,14 @@ sub _open2_for {
                       # if the stdin went away, we'll never get Shere
                       # so it's not a big deal to simply give up on !defined
                       if (!defined($len) or 0 == length($to_send)) {
+                        log_trace { "Got EOF or error when writing fatnode data to filehandle, unwatching it" };
                         Object::Remote->current_loop
                                       ->unwatch_io(
                                           handle => $foreign_stdin,
                                           on_write_ready => 1
                                         );
+                      } else {
+                          log_trace { "Sent $len bytes of fatnode data to remote side" };
                       }
                     }
                   );
@@ -93,6 +102,7 @@ END
   $text .= "ENDFAT\n";
   $text .= <<'END';
 eval $Object::Remote::FatNode::DATA;
+die $@ if $@;
 END
   $text .= "__END__\n";
   return $text;