jberger / Mojo-IOLoop-ForkCall

Deprecated! Use Mojo::IOLoop::Subprocess instead
https://mojolicious.org/perldoc/Mojo/IOLoop/Subprocess
5 stars 2 forks source link

Not work on Windows if child process take long time #10

Open tadegenban opened 7 years ago

tadegenban commented 7 years ago

use strict; use warnings; use 5.012; use Mojo::IOLoop::ForkCall;

my $fork = Mojo::IOLoop::ForkCall->new; $fork->run(sub { sleep 200;return 'success' }, [], sub { my ( $fork, $err, @ret) = @_; say $err if $err; say @ret;} );

$fork->ioloop->start;

======== run this test script on Windows, I will got : an existing connection was forcibly closed by the remote host. at lib/perl5/Mojo/IOLoop/ForkCall.pm line 132

But If I set sleep 200 to => sleep 20, it's will be OK

CandyAngel commented 7 years ago

This seems to happen if the child takes more than 120 seconds to finish. I think Windows is closing the socket connection used by IO::Pipely due to inactivity.

tadegenban commented 7 years ago

Another test script to demonstrate the pipe will not keep-alive on windows, and closed after 120s

use strict; use warnings; use 5.012; use IO::Pipely 'pipely';

my ($uni_read, $uni_write) = pipely(type => 'inet'); my $n = 1; while ( $n < 130 ) {

print $uni_write "$n"; # if remove the comment mark, everything ok, pipe will not closed

sleep 1;
$n++;

}

print $uni_write "whee inet\n"; my $uni_input = <$uni_read>; chomp $uni_input; say $uni_input;

jberger commented 7 years ago

doesn't that second example show that the problem is not in ForkCall but in windows? It is unfortunate but I'm not sure what could be done to prevent it.

CandyAngel commented 7 years ago

A workaround might be to use socketpairly() instead of pipely() and then have the parent keep-alive using its side of the "pipe".