Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the MCE CPAN distribution.

Report information
The Basics
Id: 102802
Status: resolved
Priority: 0/
Queue: MCE

People
Owner: Nobody in particular
Requestors: KARASIK [...] cpan.org
Cc:
AdminCc:

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



Subject: wrong procedure in die_handle for detecting if code is executing inside eval
Hello Mario, We've hit a bug that appers to shut down MCE on a valid die inside eval, which itself calls more functions. I've attached the patch that fixes the problem and hopefully demonstrates how it has arisen. However I personally think that checking for "eval" string is questionable, wouldn't just "if (!defined $^S || $^S)" be enough? Sincerely, Dmitry
Subject: patch
Download patch
application/octet-stream 436b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 08:58:13 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
"if (!defined $^S || $^S)" is not consistent in threads and the reason for checking the eval string. I cannot go back to doing "if (!defined $^S || $^S)" unfortunately. Thank you for the patch. I will make a new MCE release.
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 09:11:57 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
MCE itself runs inside an eval block, thus working in IPerl (Devel-IPerl on CPAN) on top of IPython. This is not possible with "if (!defined $^S || $^S)". This is the 2nd reason for checking the "eval" string. Basically, I cannot go back to doing "if (!defined $^S || $^S)".
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 09:52:36 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
I cannot add the m modifier to the regular expression. That will break the die handler in other use cases. Please provide the Carp::longmess() output from the app which failed without the m modifier. Thank you.
Hi, here's a stacktrace that kills it: at /usr/share/perl5/DBIx/Class/Exception.pm line 72 DBIx::Class::Exception::throw('DBIx::Class::Exception', 'Unable to satisfy requested constraint \'primary\', no values...', 0) called at /usr/share/perl5/DBIx/Class/Schema.pm line 1088 DBIx::Class::Schema::throw_exception('NzDB::DB=HASH(0x8c2fac8)', 'Unable to satisfy requested constraint \'primary\', no values...') called at /usr/share/perl5/DBIx/Class/ResultSource.pm line 1982 DBIx::Class::ResultSource::throw_exception('DBIx::Class::ResultSource::Table=HASH(0x8cabee0)', 'Unable to satisfy requested constraint \'primary\', no values...') called at /usr/share/perl5/DBIx/Class/ResultSet.pm line 3585 DBIx::Class::ResultSet::throw_exception('DBIx::Class::ResultSet=HASH(0x8ee3240)', 'Unable to satisfy requested constraint \'primary\', no values...') called at /usr/share/perl5/DBIx/Class/ResultSet.pm line 869 DBIx::Class::ResultSet::_build_unique_cond('DBIx::Class::ResultSet=HASH(0x8ee3240)', 'primary', 'HASH(0x8eddb88)', 'croak_on_nulls') called at /usr/share/perl5/DBIx/Class/ResultSet.pm line 792 DBIx::Class::ResultSet::__ANON__() called at /usr/share/perl5/Try/Tiny.pm line 71 eval {...} called at /usr/share/perl5/Try/Tiny.pm line 67 Try::Tiny::try('CODE(0x354c480)') called at /usr/share/perl5/DBIx/Class/ResultSet.pm line 793 DBIx::Class::ResultSet::find('DBIx::Class::ResultSet=HASH(0x8ee3240)', 'HASH(0x8ee30f0)') called at /usr/share/perl5/DBIx/Class/ResultSet.pm line 2607 DBIx::Class::ResultSet::find_or_create('DBIx::Class::ResultSet=HASH(0x8ee3240)', 'HASH(0x8ee30f0)') called at b.pl line 13
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 13:58:57 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
Dmitry, thank you for that. This is a hard problem to solve actually. Are you able to provide the b.pl script? That will be very helpful. I'd like to reproduce this and want to ensure the problem is solved. Thank you.
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 15:20:54 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
Once again, thank you for the stack trace. Am getting similar results and see a pattern.
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 15:17:26 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
Ok, am able to reproduce this with Try::Tiny and the sample db examples in MCE. Will have an update soon. Thank you.
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Mon, 16 Mar 2015 15:17:26 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
Ok, am able to reproduce this with Try::Tiny and the sample db examples in MCE. Will have an update soon. Thank you.
MCE 1.602 has been released resolving the issue. Thank you.
Hello Mario, Thank for for the quick fix! However I don't think that this fixes the problem, which is more general. One can't expect that try::Tiny is a special module, there are hundreds of modules on CPAN that wrap eval {}. I understand that you're protecting from cases inside threads, where $^S is never 0 (because threads themselves run inside eval), but consider this case also: # perl -MCarp -Mthreads -le 'eval { async { $SIG{__DIE__} = sub { print Carp::longmess }; eval { die } }->join }' at -e line 1 thread 1 eval {...} called at -e line 1 thread 1 main::__ANON__() called at -e line 1 thread 1 eval {...} called at -e line 1 thread 1 where one cannot tell whether the eval is inside or outside the thread. I see why you say that the problem is hard, and a good half of that is the fault of Perl itself. Unfortunately I cannot suggest a good general solution, but at least, I think, one can make a good solution for those 90% cases where we're talking about non-thread (or main-thread) environment, something like this: if ( $INC{'threads.pm'} && threads->id != 0) { # this is thread env, check hacky stack trace } else { # this is normal env, trust $^S } Hope this makes sense, Dmitry
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Tue, 17 Mar 2015 10:42:49 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
There was a time when the hack was not there. In the past, received a few complaints on the die handler being at fault for checking $^S (likely running threads). There is also the use case for running MCE inside an eval statement; e.g. Devel-IPerl. All of that is what got me to having the hack. Your solution seems like an elegant approach to this madness. Thus, am going to release 1.603. Thank you, Mario
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Tue, 17 Mar 2015 11:53:38 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
if ( $INC{'threads.pm'} && threads->id != 0 || $ENV{PERL_IPERL_RUNNING} ) { # this is thread env or running inside IPerl, check hacky stack trace } else { # this is normal env, trust $^S } Zaki added added a couple environment variables today. https://github.com/zmughal/p5-Devel-IPerl/commit/5ee5d6890bf5025cf78dba1bc249f92294dda7e3 Thank you, Mario
Subject: Re: [rt.cpan.org #102802] wrong procedure in die_handle for detecting if code is executing inside eval
Date: Tue, 17 Mar 2015 12:01:46 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
will not forget the missing parens :) if ( ( $INC{'threads.pm'} && threads->id != 0 ) || $ENV{PERL_IPERL_RUNNING} ) { # this is thread env or running inside IPerl, check hacky stack trace } else { # this is normal env, trust $^S }
Excellent, thank you!
MCE 1.603 has been released.