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

Memory leak when thread terminated abnormally #13092

Open
p5pRT opened this issue Jul 9, 2013 · 5 comments
Open

Memory leak when thread terminated abnormally #13092

p5pRT opened this issue Jul 9, 2013 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 9, 2013

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

Searchable as RT118815$

@p5pRT
Copy link
Author

p5pRT commented Jul 9, 2013

From haze@arpstorm.net


[Please describe your issue here]

When a thread terminated abnormally ( ie a die ) erl is leaking memory

use strict;
use threads;

sub dummy { die ; };

threads->create( \&dummy );

while( 1 ) {
  my @​dead = threads->list( threads​::joinable );
  foreach my $t ( @​dead ) {
  if( my $e = $t->error() ) { print "Error : $e\n" }
  $t->join;
  threads->create( \&dummy );
  }
}

Quick output from `ps`
haze 25229 66.0 11.0 400164 210952 pts/0 R+ 10​:48 0​:00 ./bin/perl
haze 25229 88.5 28.1 720400 538220 pts/0 Rl+ 10​:48 0​:01 ./bin/perl
haze 25229 85.6 39.2 927272 749800 pts/0 Rl+ 10​:48 0​:02 ./bin/perl
haze 25229 84.2 49.5 1120988 947808 pts/0 Rl+ 10​:48 0​:03 ./bin/perl

Replacing the die call in the dummy sub with a return does not trigger this

@p5pRT
Copy link
Author

p5pRT commented Jul 9, 2013

From haze@arpstorm.net

Not sure what happened to the end of the perlbug report; but here it is



Flags​:
  category=core
  severity=high


Site configuration information for perl 5.18.0​:

Configured by haze at Tue Jul 9 10​:38​:22 BST 2013.

Summary of my perl5 (revision 5 version 18 subversion 0) configuration​:

  Platform​:
  osname=linux, osvers=2.6.32-279.1.1.el6.x86_64, archname=x86_64-
linux-thread-multi
  uname='linux haze.arpstorm.net 2.6.32-279.1.1.el6.x86_64 #1 smp tue
jul 10 11​:24​:23 cdt 2012 x86_64 x86_64 x86_64 gnulinux '
  config_args=''
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -
pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -
fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.4.6 20110731 (Red Hat 4.4.6-3)',
gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib
/lib64 /usr/lib64 /usr/local/lib64
  libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.12'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-
protector'

Locally applied patches​:


@​INC for perl 5.18.0​:
  /home/haze/perl/share/perl5
  /home/haze/perl/lib64/perl5
  /home/haze/perl-18/lib/site_perl/5.18.0/x86_64-linux-thread-multi
  /home/haze/perl-18/lib/site_perl/5.18.0
  /home/haze/perl-18/lib/5.18.0/x86_64-linux-thread-multi
  /home/haze/perl-18/lib/5.18.0
  .


Environment for perl 5.18.0​:
  HOME=/home/haze
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
 
PATH=/usr/local/bin​:/bin​:/usr/bin​:/usr/local/sbin​:/usr/sbin​:/sbin​:/home/
haze/bin
  PERL5LIB=/home/haze/perl/share/perl5​:/home/haze/perl/lib64/perl5
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jul 9, 2013

From [Unknown Contact. See original ticket]

Not sure what happened to the end of the perlbug report; but here it is



Flags​:
  category=core
  severity=high


Site configuration information for perl 5.18.0​:

Configured by haze at Tue Jul 9 10​:38​:22 BST 2013.

Summary of my perl5 (revision 5 version 18 subversion 0) configuration​:

  Platform​:
  osname=linux, osvers=2.6.32-279.1.1.el6.x86_64, archname=x86_64-
linux-thread-multi
  uname='linux haze.arpstorm.net 2.6.32-279.1.1.el6.x86_64 #1 smp tue
jul 10 11​:24​:23 cdt 2012 x86_64 x86_64 x86_64 gnulinux '
  config_args=''
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -
pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -
fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.4.6 20110731 (Red Hat 4.4.6-3)',
gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib
/lib64 /usr/lib64 /usr/local/lib64
  libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.12'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-
protector'

Locally applied patches​:


@​INC for perl 5.18.0​:
  /home/haze/perl/share/perl5
  /home/haze/perl/lib64/perl5
  /home/haze/perl-18/lib/site_perl/5.18.0/x86_64-linux-thread-multi
  /home/haze/perl-18/lib/site_perl/5.18.0
  /home/haze/perl-18/lib/5.18.0/x86_64-linux-thread-multi
  /home/haze/perl-18/lib/5.18.0
  .


Environment for perl 5.18.0​:
  HOME=/home/haze
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
 
PATH=/usr/local/bin​:/bin​:/usr/bin​:/usr/local/sbin​:/usr/sbin​:/sbin​:/home/
haze/bin
  PERL5LIB=/home/haze/perl/share/perl5​:/home/haze/perl/lib64/perl5
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jul 14, 2013

From @iabyn

On Tue, Jul 09, 2013 at 03​:14​:08AM -0700, Hazel wrote​:

# New Ticket Created by Hazel
# Please include the string​: [perl #118815]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=118815 >

-----------------------------------------------------------------
[Please describe your issue here]

When a thread terminated abnormally ( ie a die ) erl is leaking memory

use strict;
use threads;

sub dummy { die ; };

threads->create( \&dummy );

while( 1 ) {
my @​dead = threads->list( threads​::joinable );
foreach my $t ( @​dead ) {
if( my $e = $t->error() ) { print "Error : $e\n" }
$t->join;
threads->create( \&dummy );
}
}

Quick output from `ps`
haze 25229 66.0 11.0 400164 210952 pts/0 R+ 10​:48 0​:00 ./bin/perl
haze 25229 88.5 28.1 720400 538220 pts/0 Rl+ 10​:48 0​:01 ./bin/perl
haze 25229 85.6 39.2 927272 749800 pts/0 Rl+ 10​:48 0​:02 ./bin/perl
haze 25229 84.2 49.5 1120988 947808 pts/0 Rl+ 10​:48 0​:03 ./bin/perl

Replacing the die call in the dummy sub with a return does not trigger this

I'm not certain why there's a difference in behaviour between die and
return, but note that the underlying issue here is not that die leaks
memory, but that you're cloning the @​dead list of reapable threads into
each new thread, which is causing the memory associated with each thread
to live on indefinitely.

If you change the code slightly so that the new threads are created
outside of the scope of @​dead, you'll see that the leak goes away​:

  while( 1 ) {
  my $count;
  {
  my @​dead = threads->list( threads​::joinable );
  $count = @​dead;
  foreach my $t ( @​dead ) {
  if( my $e = $t->error() ) { print "Error : $e\n" }
  $t->join;
  }
  }
  threads->create( \&dummy ) for 1..$count;
  }

Similarly, this much reduced demo doesn't leak​:

  threads->create(sub {die})->join while 1;

--
The optimist believes that he lives in the best of all possible worlds.
As does the pessimist.

@p5pRT
Copy link
Author

p5pRT commented Jul 14, 2013

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

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