workaround for bug in trac that wants to write to PYTHON_EGG_CACHE

12 03 2009

I upgraded trac on a qa-site the other day, but then found I was getting “500 internal server error” about every other post.

Investigating revealed a log barf disguised as a stack trace, the final line of which was:

[Thu Mar 12 14:47:23 2009] [error] [client 24.16.139.248] PythonHandler trac.web.modpython_frontend: ExtractionError: Can’t extract file(s) to egg cache\n\nThe following error occurred while trying to extract file(s) to the Python egg\ncache:\n\n  [Errno 13] Permission denied: ‘/www/sites/fluffy/trac/.egg-cache’\n\nThe Python egg cache directory is currently set to:\n\n  /www/sites/fluffy/trac/.egg-cache\n\nPerhaps your account does not have write access to this directory?  You can\nchange the cache directory by setting the PYTHON_EGG_CACHE environment\nvariable to point to an accessible directory.\n, referer: http://fluffy.qa-site.com/trac/wiki/BuildFlexSdk?action=edit

I tried a simple solution, by creating the directory .egg-cache and giving apache write access.  But that’s no good.

Alternately, you could change the location of the environment variable PYTHON_EGG_CACHE.

You can do this with CGI, A bit better of a fix is to add the following line to your httpd.conf

SetEnv PYTHON_EGG_CACHE /tmp

Luckily, a lot of other people have seen this problem, and some of them even know a bit about mod_python

A helpful google search turned up a trac mailing list post gave me the hint I needed.

Thanks to Django’s funky setup, a lot of people have discovered that mod_python doesn’t take SetEnv.  I don’t know if this is a bug or a design flaw (perhaps with some justification).

Anyway here’s the hack for mod_python users, instead of SetEnv, use PythonOption:

PythonOption PYTHON_EGG_CACHE /tmp


Actions

Information

5 responses

12 03 2009
Graham Dumpleton

SetEnv is for setting process environment variables of processes spawned from Apache, such as CGI, not for setting process environment variables of the Apache child worker processes themselves. Some Python web frameworks that support mod_python screw with this notion though and push SetEnv variables into the Apache child worker processes environment when they shouldn’t be. Thus why SetEnv works for some applications and not others.

12 03 2009
fijiaaron

Thanks for the clarification, graham. I’ll defitely be following your blog to look for more well written explanations like this:

http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html

2 04 2009
Jose

You’re da man!!! Thanks a lot for your tip… Worked for me in Trac. I was getting crazy with SetEnv at httpd.conf and finally add “PythonOption PYTHON_EGG_CACHE /tmp” did the trick…

;)

5 09 2009
jtw90210

thanks, Graham. You’re the only one who seemed to know about this problem. I updated the Trac Wiki http://trac.edgewall.org/wiki/TracModPython

7 09 2009
fijiaaron

Hey, I saved my own bacon again on this one. That’s why I wrote a blog.

Also, don’t forget to:

chown -R :apache /path/to/svn/repository
chmod -R g+w /path/to/svn/repository/db
when you get:

svn: Can’t create directory ‘/path/to/svn/repository/db/transactions/0-1.txn’: Permission denied

Leave a comment