Skip to content

Commit 2608ac1

Browse files
committed
fix hanging on Windows (RT#71319)
1 parent 57dc51e commit 2608ac1

2 files changed

Lines changed: 64 additions & 17 deletions

File tree

t/100_flush_bug-win32.pl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
use strict;
3+
use IO::Socket::INET;
4+
5+
my @res = (
6+
["OK\r\n", 1],
7+
["ERROR\r\n", 0],
8+
["\r\nERROR\r\n", 0],
9+
["FOO\r\nERROR\r\n", 0],
10+
["FOO\r\nOK\r\nERROR\r\n", 0],
11+
["\r\n\r\nOK\r\n", 0],
12+
["END\r\n", 0],
13+
);
14+
15+
16+
my $testaddr = shift || die;
17+
my $sock = IO::Socket::INET->new(
18+
LocalAddr => $testaddr,
19+
Proto => 'tcp',
20+
ReuseAddr => 1,
21+
Listen => 1,
22+
) or die "cannot open $testaddr: $!";
23+
my $csock = $sock->accept();
24+
while (defined (my $buf = <$csock>)) {
25+
my $res = shift @res;
26+
print $csock $res->[0];
27+
}
28+
close $csock;
29+
close $sock;
30+
exit 0;

t/100_flush_bug.t

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ my $sock = IO::Socket::INET->new(
1313
ReuseAddr => 1,
1414
);
1515

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

34-
my $pid = fork;
35-
die "Cannot fork because: '$!'" unless defined $pid;
36-
unless ($pid) {
37-
38-
my $sock = IO::Socket::INET->new(
39-
LocalAddr => $testaddr,
40-
Proto => 'tcp',
41-
ReuseAddr => 1,
42-
Listen => 1,
43-
) or die "cannot open $testaddr: $!";
44-
my $csock = $sock->accept();
45-
while (defined (my $buf = <$csock>)) {
46-
my $res = shift @res;
47-
print $csock $res->[0];
35+
my $processobj;
36+
if ($^O eq 'MSWin32') {
37+
require Win32::Process;
38+
Win32::Process::Create($processobj,
39+
"$^X",
40+
"$^X t/100_flush_bug-win32.pl $testaddr",
41+
0,
42+
32 + 134217728, #NORMAL_PRIORITY_CLASS + CREATE_NO_WINDOW
43+
".") || die $^E;
44+
45+
} else {
46+
my $pid = fork;
47+
die "Cannot fork because: '$!'" unless defined $pid;
48+
unless ($pid) {
49+
50+
my $sock = IO::Socket::INET->new(
51+
LocalAddr => $testaddr,
52+
Proto => 'tcp',
53+
ReuseAddr => 1,
54+
Listen => 1,
55+
) or die "cannot open $testaddr: $!";
56+
my $csock = $sock->accept();
57+
while (defined (my $buf = <$csock>)) {
58+
my $res = shift @res;
59+
print $csock $res->[0];
60+
}
61+
close $csock;
62+
close $sock;
63+
exit 0;
4864
}
49-
close $csock;
50-
close $sock;
51-
exit 0;
5265
}
5366

5467
# give the forked server a chance to startup
@@ -60,3 +73,7 @@ for (@res) {
6073
($_->[0] =~ s/\W//g);
6174
is $memd->flush_all, $_->[1], $_->[0];
6275
}
76+
77+
if ($processobj) {
78+
$processobj->Wait(1000) or $processobj->Kill(0);
79+
}

0 commit comments

Comments
 (0)