Skip to content

Commit 9269c4f

Browse files
ancientwizarddjzort
authored andcommitted
Re-applied test update to support OS's that dont support using
USR1 & USR2; replaced with HUP and INT for OS's (Windows) Confirmed that the Perl Interrupt patch and it's alternative work suitably well at protecting against the SEGV caused by Oracle instant client non-Perl worker threads.
1 parent b042c00 commit 9269c4f

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

t/91-segv-fork.t

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ package DB::Fork;
101101

102102
use strict;
103103
use warnings;
104+
use Carp;
104105
use Time::HiRes qw| usleep |;
105106
use DBI;
106107
use Test::More;
@@ -109,12 +110,13 @@ use Data::Dumper;
109110
use lib 't/lib';
110111
use DBDOracleTestLib qw/ db_handle /;
111112

112-
113113
our $VERSION;
114114
our $VERBOSE;
115115
our $ENABLED;
116116
our $CHILDREN;
117117
our $PARENT;
118+
our $SIG_PING;
119+
our $SIG_EXIT;
118120

119121
our $ONETHR :shared;
120122

@@ -123,6 +125,27 @@ BEGIN {
123125
$VERBOSE = $main::VERBOSE || 0;
124126
$CHILDREN = [];
125127
$PARENT = $$;
128+
$SIG_PING = 'USR1';
129+
$SIG_EXIT = 'USR2';
130+
131+
eval {
132+
local $SIG{__WARN__} = sub
133+
{
134+
croak @_;
135+
};
136+
137+
## Not all OS's support USR1 / USR2
138+
$SIG_PING = 'USR1';
139+
$SIG_EXIT = 'USR2';
140+
local $SIG{$SIG_PING} = sub { 1; };
141+
local $SIG{$SIG_EXIT} = sub { 1; };
142+
} or
143+
do {
144+
note "# Using HUP as alternative to unsupported USR1 (PING/ACK)\n";
145+
note "# Using INT as alternative to unsupported USR2 (EXIT)\n";
146+
$SIG_PING = 'HUP';
147+
$SIG_EXIT = 'INT';
148+
};
126149

127150
# DBI->trace(9);
128151
}
@@ -204,7 +227,7 @@ sub ping
204227
my $olimit = 3 * scalar @ $CHILDREN;
205228
my $signaled = {};
206229

207-
local $SIG{USR1} = sub
230+
local $SIG{$SIG_PING} = sub
208231
{
209232
return unless $child_pid;
210233
$signaled->{$child_pid} = $child_pid;
@@ -222,9 +245,9 @@ sub ping
222245

223246
last unless $child_pid;
224247

225-
## USR1 == ping
248+
## ping
226249
usleep 100000;
227-
ok kill( 'USR1', $child_pid ), 'kill USR1(ping) ' . $child_pid;
250+
ok kill( $SIG_PING, $child_pid ), sprintf 'kill %s %d', $SIG_PING, $child_pid;
228251

229252
while ( $limit-- && ! exists $signaled->{ $child_pid } )
230253
{
@@ -242,17 +265,17 @@ QUEUE_BACKEND:
242265
my $do_ping;
243266
my $do_exit;
244267

245-
sub _USER1 { printf "# USR1=PING on-child=%d received\n", $$; return ( $do_ping = 1 ); }
246-
sub _USER2 { printf "# USR2=EXIT on-child=%d received\n", $$; return ( $do_exit = 1 ); }
268+
sub _USER1 { printf "# %s=PING on-child=%d received\n", $SIG_PING, $$; return ( $do_ping = 1 ); }
269+
sub _USER2 { printf "# %s=EXIT on-child=%d received\n", $SIG_EXIT, $$; return ( $do_exit = 1 ); }
247270

248271
sub _FORK_WORKER
249272
{
250273
$do_ping = $do_exit = 0;
251274

252275
printf "# PID=%d (START)\n", $$;
253276

254-
local $SIG{USR1} = \&_USER1;
255-
local $SIG{USR2} = \&_USER2;
277+
local $SIG{$SIG_PING} = \&_USER1;
278+
local $SIG{$SIG_EXIT} = \&_USER2;
256279

257280
BUSY:
258281
while (1)
@@ -262,7 +285,8 @@ QUEUE_BACKEND:
262285
{
263286
printf "# pid=%s PING received (hold on, this is going to be a bumpy ride!)\n", $$;
264287
_connect();
265-
printf "# PARENT=%s CHILD=%d %s=kill USR1\n", $PARENT, $$, kill( 'USR1', $PARENT );
288+
## AKA PING-ACK
289+
printf "# PARENT=%s CHILD=%d %s=kill %s\n", $PARENT, $$, kill( $SIG_PING, $PARENT ), $SIG_PING;
266290
$do_ping = 0;
267291
next;
268292
}

t/92-segv-fork.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
exit(6) unless scalar @ $row == 1;
5252
# printf "# [ %s ]\n", $row->[];
5353

54-
my $usleep = int(rand(300000)) + 2000000; # 2-5 seconds
54+
my $usleep = int(rand(100000)) + 2000000; # 1-3 seconds (to speed up test!)
5555
# printf "# %02.2f seconds\n", $usleep / 1000000;
5656
usleep($usleep);
5757

t/92-segv-fork.t

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/usr/bin/env perl
22

3+
## A SEGV during this test is a sign that Perl itself lacks the patch
4+
## that allows a SIGCHLD (any interrupt) to be handedled using a worker
5+
## thread created by Oracle Instant Client.
6+
##
7+
## Consult: https://github.com/perl5-dbi/DBD-Oracle/issues/192
8+
## and: https://github.com/Perl/perl5/issues/23326
9+
## for details concerning the issue and the patch.
10+
311
use strict;
412
use warnings;
513
use Time::HiRes qw| usleep |;
@@ -107,12 +115,10 @@ QUEUE_BASICS:
107115

108116
FORK_SEGV:
109117
{
110-
# last FORK_SEGV if 1;
111-
112118
section 'FORK - SEGV';
113119

114120
my $queue = Child::Queue->new( -DEPTH => 8 );
115-
my $jobs = 80;
121+
my $jobs = 40;
116122

117123
is $queue->depth, 8, 'Queue depth';
118124
is $queue->size, 0, 'Queue size';

0 commit comments

Comments
 (0)