Thursday, July 17, 2008

Zope Crashing, MaximumRecursion & OSX Thread Stack Size

Just making a note here about a problem I had earlier today with Zope crashing under OSX and how I fixed it. This is apparently a well-known issue with Zope on some platforms including OSX and FreeBSD.

I had just made a small change to an Archetypes schema in my content class and reloaded the relevant code. When I refreshed the page Zope chugged away for a bit and then Zope just exited silently.

Using gdb I tried the request again and found that it was dying from a memory access violation.

When I exercised the same code under the testrunner I found that due to a small omission on my part I had triggered a MaximumRecursion exception.

So as it turns out there are different stack sizes for child threads. And under OSX this size is smaller than Zope requires.

Now Python 2.5 has a runtime option in the thread module to set the stack size, but Python 2.4, required for Zope 2.X, does not.

The solution I found for Python 2.4 was build Python myself, adding -DTHREAD_STACK_SIZE=0x100000 to CFLAGS in the Python Makefile. This sets to the child stack size to 1 meg which seems to be sufficient.

Now when I run the offending code in the Zope server it no longer crashes and` correctly displays the MaximumRecursion exception.

No comments: