perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: [PATCH] libperl leaks a THREAD_KEY each time it is reloaded
Date Tue, 11 Jan 2005 19:55:12 GMT
Gisle Aas wrote:
> Stas Bekman <stas@stason.org> writes:
> 
> 
>>I can't figure out whether PL_thr_key is a static global that survives
>>perl_destruct and perl_free?
> 
> 
> It is. because you find it declared in perlvars.h under the following
> heading:
> ---------------------------------------------------------->%-------------
> /****************/
> /* Truly global */
> /****************/
> 
> /* Don't forget to re-run embed.pl to propagate changes! */
> 
> /* This file describes the "global" variables used by perl
>  * This used to be in perl.h directly but we want to abstract out into
>  * distinct files which are per-thread, per-interpreter or really global,
>  * and how they're initialized.
>  *
>  * The 'G' prefix is only needed for vars that need appropriate #defines
>  * generated in embed*.h.  Such symbols are also used to generate
>  * the appropriate export list for win32. */
> 
> /* global state */
> PERLVAR(Gcurinterp,     PerlInterpreter *)
>                                         /* currently running interpreter
>                                          * (initial parent interpreter under
>                                          * useithreads) */
> #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
> PERLVAR(Gthr_key,       perl_key)       /* key to retrieve per-thread struct */
> #endif
> 
> [...]

Aha, I was grepping for the macro! Thanks.

>>If it does than this should work:
>>
>>Index: src/modules/perl/mod_perl.c
>>===================================================================
>>--- src/modules/perl/mod_perl.c	(revision 124805)
>>+++ src/modules/perl/mod_perl.c	(working copy)
>>@@ -573,6 +573,19 @@
>>      MP_threads_started = 0;
>>      MP_post_post_config_phase = 0;
>>
>>+    /* with USE_ITHREADS perl leaks pthread_key_t on every
>>+     * perl_destruct, which becomes a problem restarts: if the OS
>>+     * limit is 1024, 1024 restarts later things will start
>>+     * crashing */
>>+    /* XXX: this is a workaround for the bug in perl, once and if it's
>>+     * fixed we need to disable it for the versions that have it
>>+     * fixed */
>>+#ifdef ALLOC_THREAD_KEY
>>+    if (PL_thr_key) {
>>+        FREE_THREAD_KEY;
>>+    }
>>+#endif
>>+
> 
> 
> This would only work if the perl code is never re-entered after this.
> Is this really the case?

That's really the case

> The '#ifdef ALLOC_THREAD_KEY' is wrong AFAICT; this macro will always
> be defined.  Testing PL_thr_key as a boolean is outside of the spec of
> what pthreads define. PL_curinterp will be set if the key has
> initialized.  That's a better test.
> 
> Does things not work if you just drop in the "perl_fini" destructor I
> provided in mod_perl.c?

It works too. The latest version is:

Index: src/modules/perl/mod_perl.c
===================================================================
--- src/modules/perl/mod_perl.c (revision 124805)
+++ src/modules/perl/mod_perl.c (working copy)
@@ -573,6 +573,17 @@
      MP_threads_started = 0;
      MP_post_post_config_phase = 0;

+    /* with USE_ITHREADS perl leaks pthread_key_t on every
+     * perl_destruct, which becomes a problem restarts: if the OS
+     * limit is 1024, 1024 restarts later things will start
+     * crashing */
+    /* XXX: this is a workaround for the bug in perl, once and if it's
+     * fixed we need to disable it for the versions that have it
+     * fixed */
+    if (PL_curinterp) {
+        FREE_THREAD_KEY;
+    }
+
      MP_TRACE_i(MP_FUNC, "mod_perl sys term\n");

      modperl_env_unload();

Thanks Gisle.

so the only remaining issue is how to fix that in perl-core so it works in 
any embed perl program.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message