Skip Menu |
 

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 49722
Status: rejected
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: zefram [...] fysh.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 7F25D19B8354 for <bug-Moose [...] rt.cpan.org>; Tue, 15 Sep 2009 16:17:33 -0400 (EDT)
Received: (qmail 1713 invoked by uid 103); 15 Sep 2009 20:17:32 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 15 Sep 2009 20:17:32 -0000
Received: from pond.fysh.org (HELO pond.fysh.org) (166.84.7.109) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Tue, 15 Sep 2009 13:17:26 -0700
Received: from zefram by pond.fysh.org with local (Exim 4.69 #1 (Debian)) id 1MneSm-00082t-TN; Tue, 15 Sep 2009 21:17:20 +0100
Delivered-To: cpan-bug+Moose [...] diesel.bestpractical.com
MIME-Version: 1.0
Subject: Moose::Object DESTROY still needs to localise more
X-Spam-Status: No, hits=0.0 required=8.0 tests=
Return-Path: <zefram [...] fysh.org>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-Moose [...] rt.cpan.org
Content-Disposition: inline
Date: Tue, 15 Sep 2009 21:17:20 +0100
X-Spam-Level: *
content-type: text/plain; charset="utf-8"
Message-ID: <20090915201720.GA28694 [...] fysh.org>
To: bug-Moose [...] rt.cpan.org
From: Zefram <zefram [...] fysh.org>
X-RT-Original-Encoding: us-ascii
Content-Length: 1974
Download (untitled) / with headers
text/plain 1.9k
Re bug #48271, I see that you're now explicitly localising $?, and Try::Tiny localises $@. Those are fine. But object destruction can still clobber $!, $^E, and $., and that's still a problem. Here's an example of how clobbering $! can lose: use warnings; use strict; { package TestObj; use Moose; sub DEMOLISH { open my $fh, "<", "/bar"; if($fh) { # hypothetically might do some I/O here } } } do { my $t = TestObj->new; mkdir("/foo") } or die "mkdir failed: $!\n"; Assuming you're not root, the mkdir will fail with EACCES (Permission denied). The die attempts to put this status into an exception message. Between the mkdir and the die, though, $t gets destroyed, and its attempt at I/O fails with ENOENT (No such file or directory). It clobbers $!, and the program ends up showing the wrong error message. This is a reasonable coding pattern, and for it to work the destructor needs to localise $! to avoid clobbering it. The localisation can either go in every individual DEMOLISH method that has a chance of clobbering it, or go in Moose::Object::DESTROY. I recommend that the framework should do it. The use case for $^E is identical, because it's an auxiliary OS error code and is set in the same situations as $!. It doesn't do anything on Unix, though, so it's a little harder to demonstrate. Also more likely to be forgotten if every DEMOLISH author is responsible for localising it. $. gets changed by I/O. More specifically, the aspect of $. that behaves as a local status indicator is not the value visible in it (which is actually persistent state of some filehandle) but *which* filehandle it points at. This gets changed whenever input is performed with a different filehandle. It could be clobbered by a destructor quite similar to the one in the example I gave above. The same issues apply as with $!, $?, and the rest, but $. is even more likely to be overlooked by individual destructor authors. -zefram
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
In-Reply-To: <rt-3.6.HEAD-27252-1253045870-1964.49722-4-0 [...] rt.cpan.org>
References: <RT-Ticket-49722 [...] rt.cpan.org> <20090915201720.GA28694 [...] fysh.org> <rt-3.6.HEAD-27252-1253045870-1964.49722-4-0 [...] rt.cpan.org>
Message-ID: <a891e1bd0909170558h243e46bak97a535ca198c3545 [...] mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
X-RT-Original-Encoding: utf-8
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 1DFA64D811A for <bug-Moose [...] rt.cpan.org>; Thu, 17 Sep 2009 08:58:42 -0400 (EDT)
Received: (qmail 15750 invoked by uid 103); 17 Sep 2009 12:58:42 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 17 Sep 2009 12:58:42 -0000
Received: from mail-fx0-f212.google.com (HELO mail-fx0-f212.google.com) (209.85.220.212) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 17 Sep 2009 05:58:36 -0700
Received: by fxm8 with SMTP id 8so263259fxm.45 for <bug-Moose [...] rt.cpan.org>; Thu, 17 Sep 2009 05:58:33 -0700 (PDT)
Received: by 10.86.227.13 with SMTP id z13mr532255fgg.72.1253192310229; Thu, 17 Sep 2009 05:58:30 -0700 (PDT)
Delivered-To: cpan-bug+Moose [...] diesel.bestpractical.com
Subject: Re: [rt.cpan.org #49722] Moose::Object DESTROY still needs to localise more
Return-Path: <nothingmuch [...] woobling.org>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-Moose [...] rt.cpan.org
X-Google-Sender-Auth: bf772e41c0453093
Date: Thu, 17 Sep 2009 15:58:10 +0300
Sender: nothingmuch [...] woobling.org
X-Spam-Level: *
To: bug-Moose [...] rt.cpan.org
Content-Transfer-Encoding: quoted-printable
From: Yuval Kogman <nuffin [...] cpan.org>
RT-Message-ID: <rt-3.6.HEAD-27252-1253192334-1135.49722-0-0 [...] rt.cpan.org>
Content-Length: 2461
Download (untitled) / with headers
text/plain 2.4k
We decided not to do that because $@ and to some extend $? are much more volatile in object destruction (due to stack unwinding and global destruction) but all other variables don't correlate with destruction at all. The reason we do localize these two values because destructors often called between the point in time when $@ is set and $@ is read, but this does not apply to $!, $^E, $. etc since they do not intrinsically correlate with control flow (and therefore garbage collection). Show quoted text
>        do { my $t = TestObj->new; mkdir("/foo") } >                or die "mkdir failed: $!\n";
The problem is that in this code $! is not collected soon enough. This is a flaw in Perl that Moose cannot solve. Liewise, if TestObj::DESTROY calls a system call and $! was actually meant to be collected later then that in turn will be broken since the value is lost irrecoverably. The correct fix here would be to wrap mkdir in something like autodie which would collect all the values of the error value from global storage into something else *immediately* after the system call, as no other way is correct. FWIW, Even that is flawed, since in many programs system calls might be made at arbitrary points in the program: $SIG{CHLD} = sub { ... } wait() might set $! then the value of $! could be clobbered anywhere and at any time. This is the same limitation that errno has in C. Destructors and localization cannot guarantee in any way that the people are collecting the value of $! when they should be. Even $@ and $? are questionable, and with the current behavior they may lose meaningful values. For instance: eval { die "foo" }; handle($@); sub Foo::DESTROY { die "blah" } my $obj = Foo->new(); undef $obj; or using RAII patterns to set $? at destruction in case resource cleanup did not go well. In both of these instances, which are perfectly valid, the user would have to override Moose::Object::DESTROY to provide something that is less defensive. As for $., localizing would be even worse because if a destructor and "normal code" both read from the same filehandle (intentionally), this causes skews instead of clobbered values, which are harder to detect. The real fix would be for Perl to localize these values implicitly like it does with the regexp capture variables, or of course to provide a facility other than program globals to access this information, but that's not really going to happen...
MIME-Version: 1.0
In-Reply-To: <20090915201720.GA28694 [...] fysh.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <20090915201720.GA28694 [...] fysh.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-14816-1265329229-1591.49722-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 10
not a bug.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.