WebFaction
Community site: login faq

Hi

Last night our memcached process went down and our production site started spewing 500 errors and my inbox became cluttered with errors that look like below (i.e. some exception is thrown in the python memcached code). I've now installed a script that checks every 20 minutes if memcached is down and then brings it up if it is down. But I'm not happy that our site returns 500 errors when memcached goes down. Is that standard behaviour? Can I change it?

Here's an example of part of the error messages that were emailed to me:

Internal Server Error: /article/meet-first-mitchells-plain-school-100-matric-pass-rate_2587/
Traceback (most recent call last):
  File "/home/groundupnews/webapps/production/lib/python3.4/Django-1.8.7-py3.4.egg/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/groundupnews/webapps/production/groundup/newsroom/utils.py", line 19, in _view
    return decorated_view(request, *args, **kwargs)
  File "/home/groundupnews/webapps/production/lib/python3.4/Django-1.8.7-py3.4.egg/django/utils/decorators.py", line 102, in _wrapped_view
    result = middleware.process_request(request)
  File "/home/groundupnews/webapps/production/lib/python3.4/Django-1.8.7-py3.4.egg/django/middleware/cache.py", line 130, in process_request
    cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
  File "/home/groundupnews/webapps/production/lib/python3.4/Django-1.8.7-py3.4.egg/django/utils/cache.py", line 223, in get_cache_key
    headerlist = cache.get(cache_key, None)
  File "/home/groundupnews/webapps/production/lib/python3.4/Django-1.8.7-py3.4.egg/django/core/cache/backends/memcached.py", line 84, in get
    val = self._cache.get(key)
  File "/home/groundupnews/webapps/production/lib/python3.4/python_memcached-1.57-py3.4.egg/memcache.py", line 1089, in get
    return self._get('get', key)
  File "/home/groundupnews/webapps/production/lib/python3.4/python_memcached-1.57-py3.4.egg/memcache.py", line 1034, in _get
    server, key = self._get_server(key)
  File "/home/groundupnews/webapps/production/lib/python3.4/python_memcached-1.57-py3.4.egg/memcache.py", line 413, in _get_server
    serverhash = serverHashFunction(str(serverhash) + str(i))
  File "/home/groundupnews/webapps/production/lib/python3.4/python_memcached-1.57-py3.4.egg/memcache.py", line 65, in cmemcache_hash
    (((binascii.crc32(key) & 0xffffffff)
TypeError: 'str' does not support the buffer interface

asked 12 Jan '16, 06:23

groundupnews
113
accept rate: 0%

edited 12 Jan '16, 18:01

seanf
12.2k41836


According to this answer to this question on Stack Overflow the solution is to use pylibmc and django-pylibmc instead of python-memcached.

permanent link

answered 12 Jan '16, 18:05

seanf
12.2k41836
accept rate: 37%

Thanks for this.

(12 Jan '16, 23:04) groundupnews

Seanf's answer is fine: i.e. switch to pylibmc an django-pylibmc. However, it is also possible to continue using python-memcached. The bug I had is documented here: https://github.com/linsomniac/python-memcached/issues/70

But there's also a patch. I uninstalled python-memcached and then reinstalled the latest version from github as follows:

PYTHONPATH=$HOME/webapps/<appname>/lib/python3.4 easy_install-3.4 --install-dir=$HOME/webapps/<appname>/lib/python3.4 --script-dir=$HOME/webapps/<appname>/bin git+https://github.com/linsomniac/python-memcached.git#egg=python-memcached

Where <appname> is the name of your app.

I tested this earlier today and it seems fine. Nevertheless, switching to pylibmc might be safer for now.

permanent link

answered 12 Jan '16, 18:41

groundupnews
113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×34

question asked: 12 Jan '16, 06:23

question was seen: 1,652 times

last updated: 12 Jan '16, 23:04

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM