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

Endless loop when using encoding layer on STDERR #14362

Open
p5pRT opened this issue Dec 23, 2014 · 6 comments
Open

Endless loop when using encoding layer on STDERR #14362

p5pRT opened this issue Dec 23, 2014 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 23, 2014

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

Searchable as RT123489$

@p5pRT
Copy link
Author

p5pRT commented Dec 23, 2014

From @eserte

The following script goes into an endless loop for all modern perl versions (5.8.9 .. 5.21.7, seen on FreeBSD and Linux)​:

#!/usr/bin/perl

my $extra_len = shift || 1022; # may be somewhat smaller, down to 970 or so
binmode \*STDERR, "​:encoding(US-ASCII)";
my $foo = "\x{dc}" . "x" x $extra_len;
alarm 3;
warn "$foo\n";

__END__

My guess​: the inEncodeCall hack in PerlIO/encoding.xs was triggered, and maybe some file pointer was not advanced.

Regards,
  Slaven

@p5pRT
Copy link
Author

p5pRT commented Dec 23, 2014

From @jkeenan

On Tue Dec 23 14​:23​:50 2014, slaven@​rezic.de wrote​:

The following script goes into an endless loop for all modern perl
versions (5.8.9 .. 5.21.7, seen on FreeBSD and Linux)​:

#!/usr/bin/perl

my $extra_len = shift || 1022; # may be somewhat smaller, down to 970
or so
binmode \*STDERR, "​:encoding(US-ASCII)";
my $foo = "\x{dc}" . "x" x $extra_len;
alarm 3;
warn "$foo\n";

__END__

My guess​: the inEncodeCall hack in PerlIO/encoding.xs was triggered,
and maybe some file pointer was not advanced.

Regards,
Slaven

On Linux/amd64 (Ubuntu 14.04 LTS), find that if I run the code above I get the alarm after 3 seconds.

#####
$ perl 123489-loop.pl
Alarm clock
#####

However, when I edit the file to insert a print to STDERR statement after the assignment to $foo, I get the endless loop.

#####
$ cat 123489-loop.pl
my $extra_len = shift || 1022; # may be somewhat smaller, down to 970 or so
binmode \*STDERR, "​:encoding(US-ASCII)";
my $foo = "\x{dc}" . "x" x $extra_len;
print STDERR "$foo\n";
alarm 3;
warn "$foo\n";
#####
$ perl 123489-loop.pl
^C
#####

If, however, I print that line to STDOUT, I get the line, then the alarm in a few seconds.

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Dec 23, 2014

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

@p5pRT
Copy link
Author

p5pRT commented Jan 5, 2015

From @eserte

Dana Uto 23. Pro 2014, 14​:50​:28, jkeenan reče​:

On Tue Dec 23 14​:23​:50 2014, slaven@​rezic.de wrote​:

The following script goes into an endless loop for all modern perl
versions (5.8.9 .. 5.21.7, seen on FreeBSD and Linux)​:

#!/usr/bin/perl

my $extra_len = shift || 1022; # may be somewhat smaller, down to 970
or so
binmode \*STDERR, "​:encoding(US-ASCII)";
my $foo = "\x{dc}" . "x" x $extra_len;
alarm 3;
warn "$foo\n";

__END__

My guess​: the inEncodeCall hack in PerlIO/encoding.xs was triggered,
and maybe some file pointer was not advanced.

Regards,
Slaven

On Linux/amd64 (Ubuntu 14.04 LTS), find that if I run the code above I
get the alarm after 3 seconds.

This is already the bug reproduced, unless you have a very (!) slow CPU which needs longer than three seconds for one warn() statement :-). The alarm clock is just there in case somebody wants to turn this into a test script which must not hang.

@p5pRT
Copy link
Author

p5pRT commented Jan 5, 2015

From @Leont

On Tue, Dec 23, 2014 at 11​:23 PM, slaven@​rezic.de <perlbug-followup@​perl.org

wrote​:

The following script goes into an endless loop for all modern perl
versions (5.8.9 .. 5.21.7, seen on FreeBSD and Linux)​:

#!/usr/bin/perl

my $extra_len = shift || 1022; # may be somewhat smaller, down to 970 or so
binmode \*STDERR, "​:encoding(US-ASCII)";
my $foo = "\x{dc}" . "x" x $extra_len;
alarm 3;
warn "$foo\n";

__END__

My guess​: the inEncodeCall hack in PerlIO/encoding.xs was triggered, and
maybe some file pointer was not advanced.

This sounds like a duplicate of #117537

Leon

@p5pRT
Copy link
Author

p5pRT commented Sep 9, 2019

From @eserte

Dana Tue, 23 Dec 2014 14​:23​:50 -0800, slaven@​rezic.de reče​:

The following script goes into an endless loop for all modern perl
versions (5.8.9 .. 5.21.7, seen on FreeBSD and Linux)​:

#!/usr/bin/perl

my $extra_len = shift || 1022; # may be somewhat smaller, down to 970
or so
binmode \*STDERR, "​:encoding(US-ASCII)";
my $foo = "\x{dc}" . "x" x $extra_len;
alarm 3;
warn "$foo\n";

__END__

My guess​: the inEncodeCall hack in PerlIO/encoding.xs was triggered,
and maybe some file pointer was not advanced.

Good news​: starting with perl 5.29.9 the script does not hang anymore (checked on various FreeBSD and Linux systems).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants