perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Kobes <ra...@theoryx5.uwinnipeg.ca>
Subject Re: hanging proxy and $base_server_pool->cleanup_register
Date Sat, 11 Dec 2004 06:15:38 GMT
On Wed, 8 Dec 2004, Stas Bekman wrote:

> Joe Schaefer wrote:
> > Stas Bekman <stas@stason.org> writes:
> >
> >
> >>Now cleanup_register() ties a perl interpreter and doesn't release it
> >>until that cleanup handler is run. So that call:
> >>   $base_server_pool->cleanup_register(sub { Apache::OK });
> >>was tieing an interpreter, but wasn't releasing it (since the pool is
> >>freed at the child_exit only). And therefore we had a lack of
> >>available interpreters and voilĂ  the problem we had that we all saw.
> >>
> >>I'll fix that shortly in the way suggested in my previous followup.
> >
> >
> > ++stas, nice work here!
>
> Thanks :)
>
> So the new function is:
>
>    Apache::ServerUtil::server_shutdown_register_cleanup()
>
> The only minor problem is that I had to duplicate code from APR_Pool.h:
>
> /* XXX: the mpxs_cleanup_t and mpxs_cleanup_run are almost dups with
>   * code in APR__Pool.h (minus interpr member which is not used
>   * here. They should be moved to modperl_common_util - the problem is
>   * modperl_interp_t *, which can't live in modperl_common_* since it
>   * creates a dependency on mod_perl. A possible solution is to use
>   * void * for that slot and cast it to modperl_interp_t * when used
>   */
>
> Anybody wants to tackle this?  I think the pool stuff is still dependent
> on mod_perl, since it has modperl_interp_t in it.

Here's a partial stab at this, moving mpxs_cleanup_t to
src/modules/perl/modperl_common_types.h:
========================================================
Index: src/modules/perl/modperl_common_types.h
===================================================================
--- src/modules/perl/modperl_common_types.h	(revision 111576)
+++ src/modules/perl/modperl_common_types.h	(working copy)
@@ -24,5 +24,17 @@
     char *path_info;
 } modperl_uri_t;

+
+typedef struct {
+    SV *cv;
+    SV *arg;
+    apr_pool_t *p;
+    PerlInterpreter *perl;
+#ifdef USE_ITHREADS
+    void *interp;
+#endif
+} mpxs_cleanup_t;
+
+
 #endif /* MODPERL_COMMON_TYPES_H */

Index: xs/APR/Pool/APR__Pool.h
===================================================================
--- xs/APR/Pool/APR__Pool.h	(revision 111576)
+++ xs/APR/Pool/APR__Pool.h	(working copy)
@@ -13,6 +13,8 @@
  * limitations under the License.
  */

+#include "modperl_common_types.h"
+
 #define MP_APR_POOL_NEW "APR::Pool::new"

 typedef struct {
@@ -229,16 +231,6 @@
 }


-typedef struct {
-    SV *cv;
-    SV *arg;
-    apr_pool_t *p;
-    PerlInterpreter *perl;
-#ifdef USE_ITHREADS
-    modperl_interp_t *interp;
-#endif
-} mpxs_cleanup_t;
-
 /**
  * callback wrapper for Perl cleanup subroutines
  * @param data   internal storage
@@ -302,6 +294,7 @@
 static MP_INLINE void mpxs_apr_pool_cleanup_register(pTHX_ apr_pool_t *p,
                                                      SV *cv, SV *arg)
 {
+    modperl_interp_t *interp;
     mpxs_cleanup_t *data =
         (mpxs_cleanup_t *)apr_pcalloc(p, sizeof(*data));

@@ -313,8 +306,9 @@
     /* make sure interpreter is not putback into the mip
      * until this cleanup has run.
      */
-    if ((data->interp = MP_THX_INTERP_GET(data->perl))) {
-        data->interp->refcnt++;
+    if ((interp = MP_THX_INTERP_GET(data->perl))) {
+        interp->refcnt++;
+        data->interp = interp;
     }
 #endif

Index: xs/Apache/ServerUtil/Apache__ServerUtil.h
===================================================================
--- xs/Apache/ServerUtil/Apache__ServerUtil.h	(revision 111576)
+++ xs/Apache/ServerUtil/Apache__ServerUtil.h	(working copy)
@@ -13,6 +13,8 @@
  * limitations under the License.
  */

+#include "modperl_common_types.h"
+
 #define mpxs_Apache__ServerUtil_restart_count modperl_restart_count

 #define mpxs_Apache__ServerRec_method_register(s, methname)     \
@@ -29,13 +31,6 @@
  * void * for that slot and cast it to modperl_interp_t * when used
  */

-typedef struct {
-    SV *cv;
-    SV *arg;
-    apr_pool_t *p;
-    PerlInterpreter *perl;
-} mpxs_cleanup2_t;
-
 /**
  * callback wrapper for Perl cleanup subroutines
  * @param data   internal storage
@@ -43,7 +38,7 @@
 static apr_status_t mpxs_cleanup_run(void *data)
 {
     int count;
-    mpxs_cleanup2_t *cdata = (mpxs_cleanup2_t *)data;
+    mpxs_cleanup_t *cdata = (mpxs_cleanup_t *)data;
     dTHXa(cdata->perl);
     dSP;

@@ -84,7 +79,7 @@
 void mpxs_Apache__ServerUtil_server_shutdown_cleanup_register(pTHX_ SV *cv,
                                                               SV *arg)
 {
-    mpxs_cleanup2_t *data;
+    mpxs_cleanup_t *data;
     apr_pool_t *p;

     MP_CROAK_IF_POST_POST_CONFIG_PHASE("server_shutdown_cleanup_register");
@@ -92,7 +87,7 @@
     p = modperl_server_user_pool();
     /* must use modperl_server_user_pool here to make sure that it's run
      * before parent perl is destroyed */
-    data = (mpxs_cleanup2_t *)apr_pcalloc(p, sizeof(*data));
+    data = (mpxs_cleanup_t *)apr_pcalloc(p, sizeof(*data));
     data->cv   = SvREFCNT_inc(cv);
     data->arg  = arg ? SvREFCNT_inc(arg) : Nullsv;
     data->p    = p;

======================================================================
I'm looking at doing the same for mpxs_cleanup_run, but
am having a problem at the moment with getting the
declaration of modperl_opt_interp_unselect in the right
place.

-- 
best regards,
randy

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


Mime
View raw message