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 22:56:04 GMT
Gisle Aas wrote:
> Stas Bekman <stas@stason.org> writes:
> 
> 
>>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
> 
> 
> I would fix this comment a bit.  There isn't a pthread_key_t leaked on
> every perl_destruct.  There is a pthread_key_t leaked on every reload
> of libperl.{a,so}.
> 
> 
>>+     * 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;
>>+    }
> 
> 
> Still seems like a good idea to protect this section in a #ifdef
> USE_ITHREADS block to match when PL_curinterp follow the invariant you
> are testing for here.

Thanks for the advice, Gisle. Here is a new patch:

Index: src/modules/perl/modperl_perl_includes.h
===================================================================
--- src/modules/perl/modperl_perl_includes.h    (revision 124805)
+++ src/modules/perl/modperl_perl_includes.h    (working copy)
@@ -133,4 +133,22 @@
      } STMT_END
  #endif

+
+/* perl bug workaround: with USE_ITHREADS perl leaks pthread_key_t on
+ * every reload of libperl.{a,so} (it's allocated on the very first
+ * perl_alloc() and never freed). This becomes a problem on apache
+ * restart: if the OS limit is 1024, 1024 restarts later things will
+ * start crashing */
+/* XXX: once and if it's fixed in perl, we need to disable it for the
+ * versions that have it fixed, otherwise it'll crash because it'll be
+ * freed twice */
+#ifdef USE_ITHREADS
+#define MP_PERL_FREE_THREAD_KEY_WORKAROUND     \
+    if (PL_curinterp) {                         \
+        FREE_THREAD_KEY;                        \
+    }
+#else
+#define MP_PERL_FREE_THREAD_KEY_WORKAROUND
+#endif
+
  #endif /* MODPERL_PERL_INCLUDES_H */
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,8 @@
      MP_threads_started = 0;
      MP_post_post_config_phase = 0;

+    MP_PERL_FREE_THREAD_KEY_WORKAROUND;
+
      MP_TRACE_i(MP_FUNC, "mod_perl sys term\n");

      modperl_env_unload();

-- 
__________________________________________________________________
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