Skip Menu |

This queue is for tickets about the Parse-RecDescent CPAN distribution.

Report information
The Basics
Id: 31076
Status: resolved
Priority: 0/
Queue: Parse-RecDescent

People
Owner: Nobody in particular
Requestors: andrej.czapszys [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: v1.95.1
Fixed in: (no value)



Subject: ParseRecDescent unexpectedly dups STDERR at compile time
Scenario: My script attempts to detach from the user's terminal by closing STDIN, STDOUT, and STDERR, doing a setsid() and forking. Expected result: The ssh connection is closed when the user logs out. Actual result: The connection hangs waiting for STDERR to be closed. The problem comes from these statements: open (ERROR, ">&STDERR"); open (TRACE, ">&STDERR"); open (TRACECONTEXT, ">&STDERR"); This module is unexpectedly dupping STDERR at module load time. This was very hard to track down since Parse::RecDescent is a utility pulled in from another library. This could be better encapsulated.
From: GRANTM [...] cpan.org
On Thu Nov 29 12:04:24 2007, axc wrote: Show quoted text
> Scenario: > My script attempts to detach from the user's terminal by closing STDIN, > STDOUT, and STDERR, doing a setsid() and forking. > > Expected result: > The ssh connection is closed when the user logs out. > > Actual result: > The connection hangs waiting for STDERR to be closed.
Just to add a 'me too' on this ticket ... The fact that our mod_perl app includes 'use Parse::RecDescent' means that if I log in and restart Apache, the new Apache process ends up with open connections to my TTY and the ssh session hangs when logging out. Not a life-threatening problem by any means but it did cause much head scratching.
From: eponymousalias [...] yahoo.com
On Thu Nov 29 12:04:24 2007, axc wrote: Show quoted text
> Actual result: > The connection hangs waiting for STDERR to be closed. > > The problem comes from these statements: > open (ERROR, ">&STDERR"); > open (TRACE, ">&STDERR"); > open (TRACECONTEXT, ">&STDERR"); > > This could be better encapsulated.
I agree. I added the following to my main-line code to resolve this, to redirect these error/trace streams to my own log file after it has been opened: do { package Parse::RecDescent; sub set_error_stream (*;$) { my $filehandle = shift; my $mode = shift || '>'; # Duplicate the given filehandle. $mode = "$mode&"; open (ERROR, $mode, $filehandle); set_autoflush(\*ERROR); open (TRACE, $mode, $filehandle); set_autoflush(\*TRACE); open (TRACECONTEXT, $mode, $filehandle); set_autoflush(\*TRACECONTEXT); } }; Parse::RecDescent::set_error_stream (Replication::Logger::LOG, '>>'); A similar routine, probably with an altered name, should be added to the shipping Parse::RecDescent package.
Subject: Re: [rt.cpan.org #31076] ParseRecDescent unexpectedly dups STDERR at compile time
Date: Sun, 4 Apr 2010 15:02:22 -0700
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
>> This could be better encapsulated.
> > I agree.
So do I. I adapted your code to create a subroutine called Parse::RecDescent_redirect_reporting_to(). It's available in the lastest release, which I just uploaded to CPAN. Thanks for the patch! Damian
From: david [...] schweikert.ch
I almost lost two days debugging the reason why a complex script using (among others) Rec::Descent was hanging a ssh session :-( Loading a Perl module should have no side effects like this and frankly, providing a function which you can call to fix things doesn't seem to be the correct fix. Cheers David
Subject: Re: [rt.cpan.org #31076] ParseRecDescent unexpectedly dups STDERR at compile time
Date: Fri, 18 Jun 2010 09:34:42 -0700
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
> I almost lost two days debugging the reason why a complex script using > (among others) Rec::Descent was hanging a ssh session :-(
I'm genuinely sorry this happened to you, David. Show quoted text
> Loading a Perl module should have no side effects like this and frankly, > providing a function which you can call to fix things doesn't seem to be > the correct fix.
Out of interest, what would you consider a correct fix, given the requirement to maintain backwards compatibility? Damian
From: david [...] schweikert.ch
On Fri Jun 18 12:35:20 2010, damian@conway.org wrote: Show quoted text
> > Loading a Perl module should have no side effects like this and frankly, > > providing a function which you can call to fix things doesn't seem to be > > the correct fix.
> > Out of interest, what would you consider a correct fix, given the > requirement to maintain backwards compatibility?
I don't know, maybe breaking backwards compatibility is required in this case. Anyway, it's not like scripts are going to break, this is required only for debugging, right? Think about the future innocent victims of this behaviour of Parse::RecDescent :-) It's really tough to find such bugs. Cheers David
Subject: Re: [rt.cpan.org #31076] ParseRecDescent unexpectedly dups STDERR at compile time
Date: Mon, 21 Jun 2010 09:13:20 -0400
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
> I don't know, maybe breaking backwards compatibility is required in > this case. Anyway, it's not like scripts are going to break, this is > required only for debugging, right? > > Think about the future innocent victims of this behaviour of > Parse::RecDescent :-) It's really tough to find such bugs.
Thanks, David. I'll think carefully about it. Damian
Parse::RecDescent has been changed to write all error/trace output to STDERR, and it no longer duplicates any filehandles. I believe that this resolves the issue. Please try version 1.967001. Thank you for the bug report and detailed feedback!