Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

WeakRefs causing panic: magic_killbackrefs - obscure but valid case #2156

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#3450 (status was 'resolved')

Searchable as RT3450$

p5pRT commented 24 years ago

From deneb@desktop.com

Created by deneb@desktop.com

I am using weak references to manage a cache of objects that I have handed out to callers. This mostly works\, but given a certain combination of cooperating classes\, I see this during cleanup​:

  panic​: magic_killbackrefs during global destruction.

This is the minimal reproducible case I can come up with​:

  $b = new broker;   $anObj = $b->getobj();

  package broker;   sub new { return bless { pool => new pooler }\, 'broker' }   sub getobj   {   my $self = shift;   my $obj = bless {}\, 'obj';   $self->{pool}->add( 'x'\, $obj );   return $obj;   }

  package pooler;   use WeakRef;   sub new { return bless {}\, 'pooler' }   sub add   {   my ( $self\, $key\, $ref ) = @​_;   push @​{ $self->{ $key } }\, $ref;   weaken $self->{ $key }[0];   return $ref;   }

Either of the following after the top two lines will avoid panic​:

  undef $anObj;   delete $b->{pool};

I tried many variants for pooler​::add(). All of the following are substitutes for the middle two lines. All ought to have the same effect.

This one also causes the panic​:

  $self->{ $key } ||= [];   my $a = $self->{ $key };   push @​$a\, $ref;   weaken $a->[0];

But neither of these do​:

  $self->{ $key } = [];   my $a = $self->{ $key };   push @​$a\, $ref;   weaken $a->[0];

  $self->{ $key } = [ $ref ];   weaken $self->{ $key }[0];

Many thanks for your time.

Perl Info ``` Flags: category=core severity=low Site configuration information for perl v5.6.0: Configured by bbuchanan at Mon Jun 12 20:33:27 PDT 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=linux, osvers=2.2.5-15, archname=i686-linux uname='linux penseur.jumpdata.com 2.2.5-15 #1 mon apr 19 23:00:46 edt 1999 i686 unknown ' config_args='-des -O -Dprefix=/dt/vendor -Dlocincpth=/dt/vendor/include -Dloclibpth=/dt/vendor/lib -Dvendorprefix=/dt/server/perl5 -Dvendorbin=/dt/server/bin -Dvendorscript=/dt/server/bin -Dvendorlib=/dt/server/lib/perl5/5.6.0 -Dvendorman1=/dt/server/man/man1 -Dvendorman3=/dt/server/man/man3 -Dvendor=desktop.com -Dappllib=/dt/islands/lib/perl5 -Dbincompat5005 -Accflags=-DPERL_POLLUTE' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) cppflags='-DPERL_POLLUTE -fno-strict-aliasing -I/dt/vendor/include' ccflags ='-DPERL_POLLUTE -fno-strict-aliasing -I/dt/vendor/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/dt/vendor/lib' libpth=/dt/vendor/lib /lib /usr/lib /usr/local/lib libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt libc=/lib/libc-2.1.1.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/dt/vendor/lib' Locally applied patches: @INC for perl v5.6.0: /dt/islands/lib/perl5 /dt/vendor/lib/perl5/5.6.0/i686-linux /dt/vendor/lib/perl5/5.6.0 /dt/vendor/lib/perl5/site_perl/5.6.0/i686-linux /dt/vendor/lib/perl5/site_perl/5.6.0 /dt/vendor/lib/perl5/site_perl /dt/server/lib/perl5/5.6.0/i686-linux /dt/server/lib/perl5/5.6.0 /dt/server/lib/perl5 . Environment for perl v5.6.0: HOME=/u/deneb LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/usr/lib/netscape:/dt/server/lib:/dt/vendor/lib LOGDIR (unset) PATH=/home/deneb/scripts:/dt/server/bin:/dt/vendor/bin:/dt/tools:/home/deneb/scripts:/dt/server/bin:/dt/vendor/bin:/dt/tools:/usr/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 24 years ago

From @gsar

On Fri\, 30 Jun 2000 02​:50​:28 PDT\, Deneb Meketa wrote​:

I am using weak references to manage a cache of objects that I have handed out to callers. This mostly works\, but given a certain combination of cooperating classes\, I see this during cleanup​:

panic​: magic_killbackrefs during global destruction.

This is due to the global destruction bug. The perl5-porters archives have lots of discussion on the subject\, but little real work.

Sarathy gsar@​ActiveState.com

p5pRT commented 24 years ago

From @vanstyn

In \200006300950\.CAA15633@​deneb\.jumpdata\.com\, Deneb Meketa writes​: :I see this during cleanup​: : : panic​: magic_killbackrefs during global destruction.

Please try this patch​:   http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-06/msg00322.html .. which appears to fix the problem you encountered.

Hugo