Make python-memcache work on memcache restarts

Bug #728359 reported by Tarek Ziadé
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Python Memcached
Fix Released
Undecided
Sean Reifschneider
Debian
New
Undecided
Unassigned

Bug Description

If you try this scenario, the lib will fail because the socket is closed on dead servers, even if those servers are back :

>>> import memcache
>>> c = memcache.Client(['127.0.0.1:11211'])
>>> c.set('1', 'ok'); c.get('1')
True
'ok'

<RESTART MEMCACHE SERVER HERE AND WAIT MORE THAN 30 SECONDS>
>>> c.get('1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tarek/dev/hg.mozilla.org/server-full-again/lib/python2.6/site-packages/python_memcached-1.45-py2.6.egg/memcache.py", line 779, in get
    return self._get('get', key)
  File "/home/tarek/dev/hg.mozilla.org/server-full-again/lib/python2.6/site-packages/python_memcached-1.45-py2.6.egg/memcache.py", line 762, in _get
    rkey, flags, rlen, = self._expectvalue(server)
  File "/home/tarek/dev/hg.mozilla.org/server-full-again/lib/python2.6/site-packages/python_memcached-1.45-py2.6.egg/memcache.py", line 874, in _expectvalue
    if line[:5] == 'VALUE':
TypeError: 'NoneType' object is unsubscriptable

My patch prevents this by resending the query once if the socket is found close. This makes python-memcached working fine when the memcache server is restarted.

Note that the patch includes changes from https://bugs.launchpad.net/python-memcached/+bug/726654 because I wrote both of them when testing this.

Revision history for this message
Tarek Ziadé (tziade) wrote :
Revision history for this message
Tarek Ziadé (tziade) wrote :

rewriting a cleaner patch

Revision history for this message
Tarek Ziadé (tziade) wrote :

Here's a cleaner attempt

It raises a _ConnectionDeadError if the socket gets closed, and _get and _set retry the command once before marking the server dead.

I am not sure what to do in set_multi, get_multi though

Revision history for this message
Hugo Beauzée-Luyssen (chouquette) wrote :

This fixes the issue for me.
Thanks for the patch !

Revision history for this message
Neganov Alexandr (ikkeps) wrote :

This works for me too, except for cases when memcached server occasionally stops (In some OSes socket.sendall(..) may not raise an exception if server is down). Here is fixed patch for 1.47 version of python-memcached.

Revision history for this message
Sean Reifschneider (jafo) wrote :

Committed ikkeps patch as r45. Thanks everyone!

Changed in python-memcached:
assignee: nobody → Sean Reifschneider (jafo)
status: New → Fix Committed
Changed in python-memcached:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.