Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTRL-C handler under Windows fails to terminate gracefully when invoked during an inner loop including a next LABEL to an outer loop. #11692

Open
p5pRT opened this issue Oct 10, 2011 · 6 comments
Labels
distro-mswin32 hasCoreDump type-core Win32 This is a meta-ticket to tag issues in the perl core which need attention on Win32. See #11925

Comments

@p5pRT
Copy link

p5pRT commented Oct 10, 2011

Migrated from rt.perl.org#101072 (status was 'open')

Searchable as RT101072$

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2011

From daoswald@gmail.com

But report attached as a text file entitled "primebugreport.rep"

See http​://www.perlmonks.org/?node_id=930504 for more details.

--

David Oswald
daoswald@​gmail.com

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2011

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2011

daoswald@gmail.com - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2011

daoswald@gmail.com - Status changed from 'open' to 'new'

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2017

From @jkeenan

Since the attachment did not end in an extension which RT is programmed to render as text, it's likely that few people saw this ticket when it originally appeared more than 5 years ago. Here it is.

James E Keenan (jkeenan@cpan.org)

##########

This is a bug report for perl from daoswald@gmail.com,
generated with the help of perlbug 1.39 running under perl 5.12.3.

This problem appears specific to Windows implementations of Perl, and seems
to be related to Perl's CTRL-C handler for Windows.

Attached is a sample "prime number generator" that uses "last LABEL" to jump
out of an inner loop to the next iteration of an outer loop. If a user hits
CTRL-C to terminate the program early, about 30% of the time he will be met
with one or more error messages, or even "line noise" in the console after
termination.

There is a writeup of this problem here:

http://www.perlmonks.org/?node_id=930504

Here is sample code:

use strict;
use warnings;

use v5.12;

use constant TOP => 1000000;

say "1 is prime.";
say "2 is prime.";

my $found = 2; # We already found 1 and 2.
OUTER: for( my $i = 3; $i < TOP; $i += 2 ) {
for( my $j = $i - 2; $j > 1; $j -= 2 ) {
( not $i % $j ) && next OUTER;
}
say "$i is prime.";
$found++;
}
say "Found $found primes between 1 and ", TOP, ".\n";

Assuming user types CTRL-C to terminate this program, about a third of the
time he will see error messages, which include (but may not be limited to)
the following (the tail end of multiple sample runs shown below).

Most of the time the error involves "Out of memory!", and some of the time
"Panic: leave_scope inconsistency..." Neither of these messages should be
happening with this code; it's not "memory consuming" code.

I tried to think of a way to create a rock-solid test to demonstrate the
issue, but came up with two problems: First, I don't know how to make the
error happen on 100% of runs. Second, I don't know how to emulate repeated
runs with CTRL-C terminations under Windows in a unit test.

Perl Info
Perl version is as follows:

This is perl 5, version 12, subversion 3 (v5.12.3) built for MSWin32-x86-multi-thread

------------------------------------------------------

perl -V returns the following:

Summary of my perl5 (revision 5 version 12 subversion 3) configuration:

Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname='Win32 strawberryperl 5.12.3.0 #1 Sun May 15 09:44:53 2011 i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_S
YS -fno-strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.4.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\Strawberry\perl\lib\CORE" -L"C:\Strawberry\c\lib"'
libpth=C:\Strawberry\c\lib C:\Strawberry\c\i686-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32
-luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lneta
pi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
libc=, so=dll, useshrplib=true, libperl=libperl512.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\Strawberry\perl\lib\CORE" -L"C:\Strawberry\c\lib"'


Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS
USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF
USE_SITECUSTOMIZE
Built under MSWin32
Compiled at May 15 2011 17:02:01
@INC:
C:/strawberry/perl/site/lib
C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib
.

-------------------------------------

Please be aware that this problem has been confirmed under other Windows/Perl
configurations as well, but does not manifest under Linux.

Below are the tail end of several sample runs where I terminated with a CTRL-C.



------------ One run -----------
..... (long list of primes omitted )....
59753 is prime.
59771 is prime.
59779 is prime.
59791 is prime.
59797 is prime.
59809 is prime. <-------I hit CTRL-C after this iteration.
Out of memory!
Use of uninitialized value $j in modulus (%) at primes.pl line 17.
Use of uninitialized value $i in modulus (%) at primes.pl line 17.
Illegal modulus zero at primes.pl line 17.
Free to wrong pool 2f4d50 not 1000 during global destruction.
-------------- Another run ------------
6043 is prime.
6047 is prime.
6053 is prime.
Out of memory!
panic: leave_scope inconsistency at C:\Users\Dave\Desktop\primes.pl line 15.
panic: leave_scope inconsistency at C:\Users\Dave\Desktop\primes.pl line 15.
panic: leave_scope inconsistency at C:\Users\Dave\Desktop\primes.pl line 15.
panic: leave_scope inconsistency at C:\Users\Dave\Desktop\primes.pl line 15.
------------- Another run --------------
4409 is prime.
4421 is prime.
4423 is prime.
Out of memory!
Use of uninitialized value $i in concatenation (.) or string at C:\Users\Dave\Desktop\primes.pl line 18.
is prime.
2 is prime.
Label not found for "next OUTER" at C:\Users\Dave\Desktop\primes.pl line 16.
------------- Another run ---------------
6271 is prime.
6277 is prime.
Out of memory!
panic: leave_scope inconsistency at primes.pl line 15.
---
Flags:
category=core
severity=none
---
Site configuration information for perl 5.12.3:

Configured by 1 at Sun May 15 16:53:01 2011.

Summary of my perl5 (revision 5 version 12 subversion 3) configuration:

Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname='Win32 strawberryperl 5.12.3.0 #1 Sun May 15 09:44:53 2011 i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.4.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\Strawberry\perl\lib\CORE" -L"C:\Strawberry\c\lib"'
libpth=C:\Strawberry\c\lib C:\Strawberry\c\i686-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
libc=, so=dll, useshrplib=true, libperl=libperl512.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\Strawberry\perl\lib\CORE" -L"C:\Strawberry\c\lib"'

Locally applied patches:


---
@INC for perl 5.12.3:
C:/strawberry/perl/site/lib
C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib
.

---
Environment for perl 5.12.3:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CyberLink\Power2Go;C:\Program Files (x86)\Samsung\Samsung PC Studio 3\;C:\Program Files (x86)\Common Files\Roxio Shared\9.0\DLLShared\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files (x86)\Calibre2\;C:\Strawberry\perl\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\c\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Research In Motion\BlackBerry Theme Studio 5.0\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CyberLink\Power2Go;C:\Program Files (x86)\Samsung\Samsung PC Studio 3\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\9.0\DLLShared\
PERL_BADLANG (unset)
SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2017

The RT System itself - Status changed from 'new' to 'open'

@toddr toddr added the Win32 This is a meta-ticket to tag issues in the perl core which need attention on Win32. See #11925 label Feb 5, 2020
@xenu xenu removed the Severity Low label Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distro-mswin32 hasCoreDump type-core Win32 This is a meta-ticket to tag issues in the perl core which need attention on Win32. See #11925
Projects
None yet
Development

No branches or pull requests

3 participants