in reply to Re^6: Is this absurd, or have I not RTFM?
in thread Is this absurd, or have I not RTFM?

Please try this

#!/usr/bin/perl -- package MyModule; use Devel::Peek; sub new { my $obj = bless { '$$' => $$ }, shift; print "## $$ IN NEW $obj ##\n"; return $obj; } sub DESTROY { print "#### BEGIN DESTROY: $$ : @_ ####\n"; print Dump( @_ ); print "###### END DESTROY: $$ : @_ ######\n"; } 1; package MyServer; use parent qw[ Net::Server::PreFork ]; our $hardtodestroy = MyModule->new; sub child_finish_hook { undef $hardtodestroy; } 1; package main; STDOUT->autoflush(1); print "## this is perl $]\n"; MyServer->run( max_servers => 1, min_servers => 1, min_spare_servers => 0, max_spare_servers => 0 );

Replies are listed 'Best First'.
Re^8: Is this absurd, or have I not RTFM?
by petermogensen (Sexton) on May 19, 2014 at 10:03 UTC
    2014/05/19-11:57:52 Server closing! #### BEGIN DESTROY: 13138 : MyModule=HASH(0x1441b78) #### SV = IV(0x190cba0) at 0x190cbb0 REFCNT = 1 FLAGS = (ROK,READONLY) #### BEGIN DESTROY: 13138 : MyModule=HASH(0x1441b78) #### SV = IV(0x190c810) at 0x190c820 REFCNT = 1 FLAGS = (ROK,READONLY) RV = 0x1441b78 SV = PVHV(0x1448880) at 0x1441b78 REFCNT = 1 FLAGS = (OBJECT,SHAREKEYS) STASH = 0x1460d40 "MyModule" ARRAY = 0x1459360 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "$$" HASH = 0x7f8f5659 SV = IV(0x1460268) at 0x1460278 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 13137 ###### END DESTROY: 13138 : MyModule=HASH(0x1441b78) ###### #### BEGIN DESTROY: 13137 : MyModule=HASH(0x1441b78) #### SV = IV(0x150bd48) at 0x150bd58 REFCNT = 1 FLAGS = (ROK,READONLY) RV = 0x1441b78 SV = PVHV(0x1448880) at 0x1441b78 REFCNT = 1 FLAGS = (OBJECT,SHAREKEYS) STASH = 0x1460d40 "MyModule" ARRAY = 0x1459360 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "$$" HASH = 0x7f8f5659 SV = IV(0x1460268) at 0x1460278 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 13137 ###### END DESTROY: 13137 : MyModule=HASH(0x1441b78) ######

    So ... as it shows process 13138 is calling DESTROY twice for the same object. Apparently it gets interrupted by shutdown half way through the first invocation (but gets far enough to crash in other ways **). What I'm wondering about is what makes Perl retry the DESTROY method for the object at a later time.

    **: This means, that if the objects DESTROY method is an XS function you can manage to call free() on a C pointer during the first invocation before you get interrupted. ... and then calling free() again in the second invocation will cause glibc to complain loudly.

      On current perl versions XS functions are not interrupted unless you activate the "unsafe" signals in some way (see perlipc).

      Um, so where is the part about the perl version?

        Oh... sorry... I didn't notice you had included that, ... since I actually already mentioned it. Perl 5.14.2 on Ubuntu:
        ## 13137 IN NEW MyModule=HASH(0x1441b78) ## ## this is perl 5.014002
      Might also need to add
      sub post_child_cleanup_hook { undef $hardtodestroy; }
        Still 3 DESTROY calls,... 2 from the same process. Only make the output less readable.
        ^C#### BEGIN DESTROY: 13406 : MyModule=HASH(0x15bfb78) #### SV = IV(0x1a8acb0) at 0x1a8acc0 REFCNT = 1 FLAGS = (ROK,READONLY) RV = 0x15bfb78 SV = PVHV(0x15c6880) at 0x15bfb78 REFCNT = 1 FLAGS = (OBJECT,SHAREKEYS) STASH = 0x15ded40 "MyModule" ARRAY = 0x15d7360 (0:7, 1:1) 2014/05/19-12:22:44 Server closing! hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "$$" HASH = 0x7f8f5659 SV = IV(0x15de268) at 0x15de278 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 13405 #### BEGIN DESTROY: 13405 : MyModule=HASH(0x15bfb78) #### SV = IV(0x1a8ac80) at 0x1a8ac90 REFCNT = 1 FLAGS = (ROK,READONLY) RV = 0x15bfb78 SV = PVHV(0x15c6880) at 0x15bfb78 REFCNT = 1 FLAGS = (OBJECT,SHAREKEYS) STASH = 0x15ded40 "MyModule" ARRAY = 0x15d7360 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "$$" #### BEGIN DESTROY: 13406 : MyModule=HASH(0x15bfb78) #### HASH = 0x7f8f5659 SV = SV = IV(0x15de268) at 0x15de278 REFCNT = 1 FLAGS = (IOK,pIOK) IV(0x1a8a920) at 0x1a8a930 REFCNT = 1 FLAGS = (ROK,READONLY) IV = 13405 RV = 0x15bfb78 ###### END DESTROY: 13405 : MyModule=HASH(0x15bfb78) ###### SV = PVHV(0x15c6880) at 0x15bfb78 REFCNT = 1 FLAGS = (OBJECT,OOK,SHAREKEYS) STASH = 0x15ded40 "MyModule" ARRAY = 0x1a91980 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "$$" HASH = 0x7f8f5659 SV = IV(0x15de268) at 0x15de278 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 13405 ###### END DESTROY: 13406 : MyModule=HASH(0x15bfb78) ######