Server death provokes AttributeError failure

Bug #1030944 reported by Ken Lalonde on 2012-07-30
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Memcached
Medium
Sean Reifschneider

Bug Description

Version 1.48: If the server dies after the client successfully connects, further attempts to use ".set" will raise exception AttributeError: 'NoneType' object has no attribute 'sendall'.

To reproduce the problem, start memcached on localhost, and run this:

import memcache, sys
mc = memcache.Client(['localhost:11211'], debug=1)
while 1:
    print mc.set("a", "b")
    sys.stdin.readline()

It will print "True" and wait for input. In a second window, kill the local memcached process.
Back at the script, hit return, and the script will fail:

MemCached: MemCache: inet:localhost:11211: connect: Connection refused. Marking dead.
Traceback (most recent call last):
  File "m.py", line 4, in <module>
    print mc.set("a", "b")
  File "/usr/local/lib/python2.7/dist-packages/memcache.py", line 565, in set
    return self._set("set", key, val, time, min_compress_len)
  File "/usr/local/lib/python2.7/dist-packages/memcache.py", line 807, in _set
    return _unsafe_set()
  File "/usr/local/lib/python2.7/dist-packages/memcache.py", line 794, in _unsafe_set
    server.send_cmd(fullcmd)
  File "/usr/local/lib/python2.7/dist-packages/memcache.py", line 1112, in send_cmd
    self.socket.sendall(cmd + '\r\n')
AttributeError: 'NoneType' object has no attribute 'sendall'

Here's one patch that will fix it (against 1.48):

--- /usr/local/lib/python2.7/dist-packages/memcache.py 2012-06-06 17:21:39.000000000 -0400
+++ ./memcache.py 2012-07-30 12:03:01.572273809 -0400
@@ -803,8 +803,8 @@
         except _ConnectionDeadError:
             # retry once
             try:
- server._get_socket()
- return _unsafe_set()
+ if server._get_socket():
+ return _unsafe_set()
             except (_ConnectionDeadError, socket.error), msg:
                 server.mark_dead(msg)
             return 0

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

Other bug subscribers