I can't figure out whether PL_thr_key is a static global that survives
perl_destruct and perl_free? 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
+
MP_TRACE_i(MP_FUNC, "mod_perl sys term\n");
modperl_env_unload();
@@ -658,6 +671,20 @@
dTHXa(scfg->mip->parent->perl);
#endif
+ {
+ pthread_key_t key;
+ int i = 0;
+ for (i=0; i<512; i++) {
+ if (pthread_key_create(&key, 0) == 0) {
+ Perl_warn(aTHX_ "%d\n", 1+i);
+ }
+ else {
+ Perl_croak(aTHX_ "failed to create the key: %d\n", i+1);
+ }
+ }
+ }
+
+
if (!modperl_post_config_require(s, pconf)) {
exit(1);
}
if not, then we need to store the key elsewhere as following:
Index: src/modules/perl/mod_perl.c
===================================================================
--- src/modules/perl/mod_perl.c (revision 124805)
+++ src/modules/perl/mod_perl.c (working copy)
@@ -51,6 +51,10 @@
return MP_post_post_config_phase;
}
+#ifdef ALLOC_THREAD_KEY
+static pthread_key_t *MP_PL_thr_key = NULL;
+#endif
+
#ifndef USE_ITHREADS
static apr_status_t modperl_shutdown(void *data)
{
@@ -192,6 +196,7 @@
int status;
char **argv;
int argc;
+ server_rec *base_server = modperl_global_get_server_rec();
#ifndef USE_ITHREADS
modperl_cleanup_data_t *cdata;
#endif
@@ -200,7 +205,6 @@
* one, if modperl_startup was called by vhost before the former
* was started */
if (MP_init_status != 2) {
- server_rec *base_server = modperl_global_get_server_rec();
PerlInterpreter *base_perl;
MP_init_status = 2; /* calls itself, so set the flag early */
@@ -213,7 +217,6 @@
#ifdef MP_TRACE
{
- server_rec *base_server = modperl_global_get_server_rec();
const char *desc = modperl_server_desc(s, p);
if (base_server == s) {
MP_TRACE_i(MP_FUNC,
@@ -271,6 +274,20 @@
PL_reentrant_buffer->_crypt_struct.current_saltbits = 0;
#endif
+ /* 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 (base_server == s) {
+ MP_PL_thr_key = &PL_thr_key;
+ Perl_warn(aTHX_ "global pthread key 0x%lx\n", MP_PL_thr_key);
+ }
+#endif
+
perl_run(perl);
#ifdef USE_ITHREADS
@@ -573,6 +590,14 @@
MP_threads_started = 0;
MP_post_post_config_phase = 0;
+#ifdef ALLOC_THREAD_KEY
+ if (MP_PL_thr_key) {
+ /* FREE_THREAD_KEY */
+ pthread_key_delete(*MP_PL_thr_key);
+ MP_PL_thr_key = NULL;
+ }
+#endif
+
MP_TRACE_i(MP_FUNC, "mod_perl sys term\n");
modperl_env_unload();
@@ -658,6 +683,20 @@
dTHXa(scfg->mip->parent->perl);
#endif
+ {
+ pthread_key_t key;
+ int i = 0;
+ for (i=0; i<512; i++) {
+ if (pthread_key_create(&key, 0) == 0) {
+ Perl_warn(aTHX_ "%d\n", 1+i);
+ }
+ else {
+ Perl_croak(aTHX_ "failed to create the key: %d\n", i+1);
+ }
+ }
+ }
+
+
if (!modperl_post_config_require(s, pconf)) {
exit(1);
}
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]