Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hanging on Windows (RT#71319) #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions t/100_flush_bug-win32.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

use strict;
use IO::Socket::INET;

my @res = (
["OK\r\n", 1],
["ERROR\r\n", 0],
["\r\nERROR\r\n", 0],
["FOO\r\nERROR\r\n", 0],
["FOO\r\nOK\r\nERROR\r\n", 0],
["\r\n\r\nOK\r\n", 0],
["END\r\n", 0],
);


my $testaddr = shift || die;
my $sock = IO::Socket::INET->new(
LocalAddr => $testaddr,
Proto => 'tcp',
ReuseAddr => 1,
Listen => 1,
) or die "cannot open $testaddr: $!";
my $csock = $sock->accept();
while (defined (my $buf = <$csock>)) {
my $res = shift @res;
print $csock $res->[0];
}
close $csock;
close $sock;
exit 0;
51 changes: 34 additions & 17 deletions t/100_flush_bug.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ my $sock = IO::Socket::INET->new(
ReuseAddr => 1,
);

#should be in 100_flush_bug-win32.pl too
my @res = (
["OK\r\n", 1],
["ERROR\r\n", 0],
Expand All @@ -31,24 +32,36 @@ if ($sock) {
}
close $sock;

my $pid = fork;
die "Cannot fork because: '$!'" unless defined $pid;
unless ($pid) {

my $sock = IO::Socket::INET->new(
LocalAddr => $testaddr,
Proto => 'tcp',
ReuseAddr => 1,
Listen => 1,
) or die "cannot open $testaddr: $!";
my $csock = $sock->accept();
while (defined (my $buf = <$csock>)) {
my $res = shift @res;
print $csock $res->[0];
my $processobj;
if ($^O eq 'MSWin32') {
require Win32::Process;
Win32::Process::Create($processobj,
"$^X",
"$^X t/100_flush_bug-win32.pl $testaddr",
0,
32 + 134217728, #NORMAL_PRIORITY_CLASS + CREATE_NO_WINDOW
".") || die $^E;

} else {
my $pid = fork;
die "Cannot fork because: '$!'" unless defined $pid;
unless ($pid) {

my $sock = IO::Socket::INET->new(
LocalAddr => $testaddr,
Proto => 'tcp',
ReuseAddr => 1,
Listen => 1,
) or die "cannot open $testaddr: $!";
my $csock = $sock->accept();
while (defined (my $buf = <$csock>)) {
my $res = shift @res;
print $csock $res->[0];
}
close $csock;
close $sock;
exit 0;
}
close $csock;
close $sock;
exit 0;
}

# give the forked server a chance to startup
Expand All @@ -60,3 +73,7 @@ for (@res) {
($_->[0] =~ s/\W//g);
is $memd->flush_all, $_->[1], $_->[0];
}

if ($processobj) {
$processobj->Wait(1000) or $processobj->Kill(0);
}