Hello segfaulters and others interested in Zope instability issues!

Our demi-god Matt Kromer from ZopeCorp has come up with a possible way
to corner the instability issue AND give you a stable, cycle-garbage
collecting Zope.

Since the problem seems, so far, to be caused by the Python Restricted
Compiler (which is used in everything from dtml expressions to python
scripts to other stuff) not completing fully collectable objects before
the Python cycle garbage collector finds them, the solution is to lock
out the gc while creating these objects. The only easy way to do this
currently is to disable the automatic gc and run manual garbage
collections only when we're pretty sure no one else is running, and at
the same time not letting anyone else run when we're running the gc.

While I can't speak for Matt but since this is a fairly urgent matter, I
believe he agrees that those experiencing segfaults are encouraged to
replace <Zope>/ZServer/PubCore/ZServerPublisher.py with the attached
file, which should work on 2.4.x and 2.5.x series Zopes, and report your
instability results.

This is the same file that can be found at:
http://zope.org/Members/matt/ZServerPublisher.py
with the difference that my version has some lines removed that are only
interesting for those that applied Matt's cprof patches mentioned
earlier on this list (which, I bet, means only me :-).

The file is small enough so that you can manually look and see that I've
installed no trojans in it :-) but those of a paranoid nature are
encouraged to download Matt's version and remove the two lines that
mention 'cprof'.

We're close guys, very close.

Cheers, Leo

PS: standard disclaimers: I don't speak for anyone else but me and I
won't be held responsible for anything you do to your site based on the
aforementioned intructions. If you break your site with them, you get to
keep both pieces :-)

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.

##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
from ZPublisher import publish_module

import ThreadLock

gc_lock = ThreadLock.allocate_lock()
active_threads = [0,]

class ZServerPublisher:
    def __init__(self, accept):
       import os
       import sys
       import gc

       gc.disable()

       while 1:
           try:
               name, request, response=accept()

               gc_lock.acquire()
               active_threads[0] = active_threads[0] + 1
               gc_lock.release()

               publish_module(
                   name,
                   request=request,
                   response=response)
           finally:
               response._finish()
               request=response=None
               gc_lock.acquire()
               a = active_threads[0] - 1

               if a == 0:
                   #sys.stderr.write("Invoking gc.collect()\n")
                   gc.collect()
               else:
                   #sys.stderr.write("Skipping gc.collect(), %d threads active\n"% a)
                   pass

               active_threads[0] = a
               gc_lock.release()

Reply via email to