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
threads::shared never frees the shared space interpreter #13149
Comments
From @nwc10With $ENV{PERL_DESTRUCT_LEVEL} set to 2, perl should free everything: $ PERL_DESTRUCT_LEVEL=2 valgrind --leak-check=full --show-reachable=yes ./perl -Ilib -e0 Note the pleasing "All heap blocks were freed -- no leaks are possible". Somewhat frustratingly, glibc's dl_open implementation has 6 still reachable $ PERL_DESTRUCT_LEVEL=2 valgrind --leak-check=full ./perl -Ilib -Mthreads -e0 so in what follows, 6 reachable objects are not our concern. But 55 blocks $ PERL_DESTRUCT_LEVEL=2 valgrind --leak-check=full ./perl -Ilib -Mthreads -Mthreads::shared -e0 With --show-reachable=yes the leaks all look like this: ==17136== 26 bytes in 1 blocks are still reachable in loss record 1 of 51 And of those 45 loss records that are from threads::shared: $ PERL_DESTRUCT_LEVEL=2 valgrind --leak-check=full --show-reachable=yes ./perl -Ilib -Mthreads -Mthreads::shared -e0 2>&1 | fgrep -c 'Perl_sharedsv_init (shared.xs:1252)' The lines in question being the last two of: void I'm not sure what the best solution is. One way would be to move Am I correct in thinking that under ithreads PL_curinterp is NULL only in Nicholas Clark |
From perl@profvince.com
Looks like the main thread can be identified by "PL_curinterp == aTHX". Vincent |
The RT System itself - Status changed from 'new' to 'open' |
From @nwc10On Mon, Aug 05, 2013 at 11:53:51AM -0300, Vincent Pit wrote:
Yes, using call_atexit() looks like a much better plan. (I'm not working on fixing this bug. I'm also not in any way hinting that Nicholas Clark |
From @tseeOn 08/05/2013 04:58 PM, Nicholas Clark wrote:
Whoever ends up fixing it should also document the fix in perlxs - it's --Steffen |
From @iabynOn Mon, Aug 05, 2013 at 03:58:24PM +0100, Nicholas Clark wrote:
I don't think that will work. Consider an embedded environment like Apache This can create multiple perl interpreters A, B, C, ... and potentially Interpreter A may run some code that calls threads->new(), creating new Similarly, B may create BS, B1, B2, ...; C may create CS, C1, C2, ..., etc. So you end up with multiple pools of interpreters. Clearly when all of Note that I'm not clear in a mod_perl-style environment, what happens -- |
From @nwc10On Mon, Aug 12, 2013 at 05:09:21PM +0100, Dave Mitchell wrote:
I think that it all still works. call_atexit() is Perl_call_atexit(), not void which get called at this point in global destruction: sv_clean_objs(); /* unhook hooks which will soon be, or use, destroyed data */ /* call exit list functions */ Safefree(PL_exitlist); PL_exitlist = NULL; SvREFCNT_dec(PL_registered_mros); and so combine that with the (PL_curinterp == aTHX) test and you can arrange If A finishes before A1 (or any of the others) PL_threadhook() already returns if (PL_threadhook(aTHX)) { I didn't realise that the code is designed to leak. In that: $ perl -Mthreads -e 'sub DESTROY {warn "I did get called"}; $o = bless [];' versus: $ perl -Mthreads -e 'sub DESTROY {warn "I did get called"}; $o = bless []; threads->new(sub {sleep 2})' ie global destruction does not run. It's clearly an error (and the loud $ cat Sleeper.pm package Sleeper; sub new { sub DESTROY { 1; __END__ Where putting one of those objects into a lexical is fine, but if it happens $ perl -MSleeper -e 'sub DESTROY {warn "I did get called in " . threads->tid}; $o = bless []; my $a = Sleeper->new' I don't have an answer for this particular digression. But I think we can clear up shared space correctly in an embedded environment Nicholas Clark |
From @iabynOn Tue, Aug 20, 2013 at 02:27:06PM +0100, Nicholas Clark wrote:
Ah, I was indeed confusing the two.
Me neither.
Oh good. -- |
Migrated from rt.perl.org#119155 (status was 'open')
Searchable as RT119155$
The text was updated successfully, but these errors were encountered: