Grokbase
x

Craig Berry (craig.a...@gmail.com)

Profile | Posts (24)

User Information

Display Name:Craig Berry
Partial Email Address:craig.a...@gmail.com
Posts:
24 total
24 in Perl 5 Porters

5 Most Recent

All Posts
1) Craig Berry Re: [perl #72666] perl documentation bug in 5.10.1
| +1 vote
ror s it. ead I included a link to the docs on deferred signals earlier. Those are written as much...
Perl 5 Porters
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Thu, Feb 11, 2010 at 1:30 PM, Marc Espie <espie@nerim.net> wrote:
> On Thu, Feb 11, 2010 at 02:08:49PM -0500, Eric Brine wrote:

>> =A0 =A0With safe signals:
>> =A0 =A01. read system call ends
>> =A0 =A02. Perl starts copying the data into the SV*
>> =A0 =A03. Signal occurs
>> =A0 =A04. Signal is noted
>> =A0 =A05. Perl finishes copying the data into the SV*
>> =A0 =A06. sysread op ends
>> =A0 =A07. Signal handler is called.
>> =A0 =A08. Exception is thrown
>> =A0 =A0No data is lost. padsv and sassign are never evaluated, so the er=

ror
>> =A0 =A0code is lost. You could miss an error or eof condition, but that'=
s it.
>> =A0 =A0* -- Or whatever sysread does between the time read ends and sysr=
ead
>> =A0 =A0ends.
>
> Is this behavior actually documented anywhere ?

I included a link to the docs on deferred signals earlier.  Those are
written as much as possible from the point of view of a Perl
programmer, but identifying possible race conditions in the
implementation really requires digging into the code in mg.c and
elsewhere and understanding both C signals and how they are used to
implement Perl signals.

It's easy to get confused between C signal handling terms that are
used by analogy when describing signals in a Perl program and C signal
handling terms that are used when describing the implementation
details of signal handling in the Perl interpreter.  That's exactly
what I did a bit earlier when I said signals were blocked for the
duration of a Perl op; that isn't quite right.  They are actually
caught and thrown away after bumping a counter.  (That's step 4 in
Eric's list.)  From the point of view of your Perl program, it's
*like* the signal is blocked until the op completes, but it's not
actually blocked from the point of view of the C implementation.

Real blocking does come into play in step 7 of Eric's list, the
calling of the Perl signal handler.  C signals are blocked while Perl
checks for any of the signals that it trapped and threw away earlier
and calls the relevant Perl signal handler.  If you scan the sources
for PERL_ASYNC_CHECK(), those are the places where C signals are
blocked while it's calling the signal handler(s) provided in your Perl
program.

If you look at the main run loop in run.c:


int
Perl_runops_standard(pTHX)
{
    dVAR;
    while ((PL_op =3D CALL_FPTR(PL_op->op_ppaddr)(aTHX))) {
        PERL_ASYNC_CHECK();
    }

    TAINT_NOT;
    return 0;
}


you can see that inside the loop you're either executing the op,
during which C signals are caught and deferred, or you're checking for
deferred signals and calling Perl signal handlers, during which C
signals are blocked.  So the window for mayhem is pretty darn narrow.

> the original example code as I read it implies that
> if a timeout occurs, the sysread didn't finish, which is wrong.

Maybe, maybe not, depending on whether the syscall gets restarted when
interrupted before control returns to Perl, which may depend on
platform, specific syscall being used, and whether stdio vs. perlio is
in use.  See the I/O section in the docs I referenced earlier.

> (the main issue with races being that they only occur unfrequently, so
> people don't notice them until they kill their critical program dead,
> or make it unreliable).

Got that right.  I appreciate your trying to improve things.  I'm in
no way guaranteeing we're 100% safe from race conditions, though we'd
sure like to know about it if you can identify one.  I'm not convinced
you have yet.  A working demonstration would really clinch the deal,
though.
2) Craig Berry VMS accounts available for open source (was Re: Smoke [5.11.2] v5.11.2-170-g4342f4d FAIL(F) openvms V8.3-1H1 (IA64/2 cpu))
| +1 vote
There is now an alternative to running your own VMS system. HP is offering free accounts for open...
Perl 5 Porters
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Fri, Dec 18, 2009 at 1:48 PM, Craig A. Berry <craigberry@mac.com> wrote:
>
> On Dec 18, 2009, at 1:03 PM, jesse wrote:

>> On a somewhat-related note, I've managed to get myself set up with a
>> "hobbyist" copy of PersonalAlpha and with VMS media. I can boot and
>> login, but I'm without license keys. Do we have a friendly source of VMS
>> keys these days or should I be trying to sign up for DECUS or its
>> successor?
>
> You'll need a free DECUSserve membership in order to get free hobbyist
> licenses. =A0See
>
> <http://labs.hoffmanlabs.com/node/1416>

There is now an alternative to running your own VMS system.  HP is
offering free accounts for open source developers.  See:

<http://www.openvms.org/stories.php?story=3D10/02/09/2319162>
3) Craig Berry Re: [perl #72666] perl documentation bug in 5.10.1
| +1 vote
required d errors Hmm. Even though signal delivery is blocked until sysread (the Perl op, not the...
Perl 5 Porters
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, Feb 9, 2010 at 10:06 PM, [email protected: e...@nerim.net]
<perlbug-followup@perl.org> wrote:
> # New Ticket Created by =A0espie@nerim.net
> # Please include the string: =A0[perl #72666]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=3D72666 >
>
>
> The example code for the use of alarm is wrong, wrong, wrong.
>
> There is a DEADLY race condition in there, the example code is overly
> optimistic:
>
> =A0 =A0 =A0 eval {
> =A0 =A0 =A0 =A0 =A0 local $SIG{ALRM} =3D sub { die "alarm\n" }; # NB: \n =
required
> =A0 =A0 =A0 =A0 =A0 alarm $timeout;
> =A0 =A0 =A0 =A0 =A0 $nread =3D sysread SOCKET, $buffer, $size;
> alarm goes off here ->
> =A0 =A0 =A0 =A0 =A0 alarm 0;
> =A0 =A0 =A0 };
> =A0 =A0 =A0 if ($@) {
> =A0 =A0 =A0 =A0 =A0 die unless $@ eq "alarm\n"; =A0 # propagate unexpecte=
d errors
> =A0 =A0 =A0 =A0 =A0 # timed out
> =A0 =A0 =A0 }
> =A0 =A0 =A0 else {
> =A0 =A0 =A0 =A0 =A0 # didn't
> =A0 =A0 =A0 }
>
> and so, we lost data from the socket. There's no way around it.
> This pattern doesn't work. Use select, or threads, or anything.

Hmm.  Even though signal delivery is blocked until sysread (the Perl
op, not the syscall) completes?  See the docs at:

<http://perldoc.perl.org/perlipc.html#Deferred-Signals-(Safe-Signals)>
4) Craig Berry Re: gmtime/localtime are busted around 2**48
| +1 vote
f89fd.diff I ran some tests with various configurations and platforms and it looked good so I...
Perl 5 Porters
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Thu, Feb 4, 2010 at 8:46 PM, Michael G Schwern <schwern@pobox.com> wrote=
:
> Michael G Schwern wrote:
>>
>> Ahh, Time::gmtime tests are now too aggressive and need to be informed
>> about the raised fence. =A0I'll fix that now.
>
> Ok, here's the updated patch. =A0Just lowered the boundaries on the
> Time::gm/localtime tests. =A0Passes all tests here.
> http://github.com/schwern/perl/commit/88e23862cae804dd8ffbb32243902c29d2f=

f89fd.diff

I ran some tests with various configurations and platforms and it
looked good so I pushed with nothing added except the MANIFEST entry
for the new test:

http://perl5.git.perl.org/perl.git/commitdiff/fc003d4

We'll see what the smokes say.

> PS =A0I discovered that if you stick a .diff on the end of a github commi=
t URL
> it'll give you a raw diff.

Good to know.  I eventually managed to do the git remote thing with
only the usual amount of psychic trauma.
5) Craig Berry Re: gmtime/localtime are busted around 2**48
| +1 vote
e: le t at b ints Or to observe the bug simply do $ perl -wle 'print scalar gmtime(2**65);' and...
Perl 5 Porters
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Wed, Feb 3, 2010 at 12:50 PM, Michael G Schwern <schwern@pobox.com> wrot=
e:
> Jesse Vincent wrote:
>>>
>>> 0001-Add-sanity-checks-for-far-far-distant-dates.patch
>>> 20d4bcb57b28e6900d1f1556528564155023876f
>>> Adds a test that we can make it to at least +/-2**52. =A0This is the
>>> missing
>>> test for 455f2c6c92e42c1a9e31268cbd491ba661f99882 which kicked this who=
le
>>> thing off.
>>>
>>
>> Schwern, Applying this patch and testing with a perl built with:
>>
>> =A0Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
>> =A0PERL_USE_DEVEL USE_64_BIT_INT USE_LARGE_FILES USE_LONG_DOUBLE
>> =A0USE_PERLIO USE_PERL_ATOF
>>
>> I can't get the test to fail/spin forever.
>> Can you give me a pointer about what I might be doing wrong?
>
> 0001-Add-sanity-checks-for-far-far-distant-dates.patch is the missing tes=
t
> for 20d4bcb57b28e6900d1f1556528564155023876f, the one where gmtime broke =
at
> 2**47. =A0That's already been fixed.
>
> What you're looking for is in
> 0002-Don-t-try-to-calculate-a-time-over-the-conservative-.patch
> I didn't separate it out into test and code patches, but you can just gra=
b
> t/op/time_loop.t from inside that patch. =A0It might not fail with 64 bit=
ints
> since the problem is a 32 bit int overflowing.

Or to observe the bug simply do

$ perl -wle 'print scalar gmtime(2**65);'

and watch with "top" or local equivalent from another session to see
it swallow cpu time in large gulps.  As Michael notes, the bug may be
triggered by different values depending on the size of an IV.

Sorry to be AWOL the last few days -- $work and such.  I've applied
the "0002-Don-t-try-to-calculate..." patch locally and started to test
it.  On OS X Leopard on PPC G5 configured with -Dusedevel -des, I see
the following failures:

t/op/time......................................................ok
t/op/time_loop.................................................gmtime(59029=
5810358705651712)
failed at op/time_loop.t line 15.
localtime(590295810358705651712) failed at op/time_loop.t line 16.
ok

[um, that's not exactly a failure, but a failure to fail, or something]

. . .
lib/Time/gmtime................................................Can't
call method "sec" on an undefined value at ../lib/Time/gmtime.t line
25.
# Looks like you planned 109 tests but ran 1.
FAILED--expected 109 tests, saw 1
lib/Time/localtime.............................................Can't
call method "sec" on an undefined value at ../lib/Time/localtime.t
line 25.
# Looks like you planned 109 tests but ran 1.
FAILED--expected 109 tests, saw 1
lib/Unicode/UCD................................................ok

so we're not quite there yet.  I'm going to see what I can see but am
not in a position to make promises about when.

spacer
Profile | Posts (24)
Home > People > Craig Berry