Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Interesting problem with memcache-client and sockets

Reply
Thread Tools

Interesting problem with memcache-client and sockets

 
 
Jakanapes
Guest
Posts: n/a
 
      02-08-2008
Hi all,

Been writing unit tests and found an interesting problem.

We're using memcache on a web app and wanted to test that the proper
exceptions would be thrown if the memcache server went down.

If memcache server is started, then killed, then a set or a get is
called, the MemCacheError exception is always rescued.

However, if memcache server is started, a set and get is called, the
server is killed, then about half the time if a set is called, no
exception. If a get is called, always an exception.

I tracked it down to the set method in memcache.rb
************************
def set(key, value, expiry = 0, raw = false)
raise MemCacheError, "Update of readonly cache" if @readonly
server, cache_key = request_setup key
socket = server.socket

value = Marshal.dump value unless raw
command = "set #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r
\n"

begin
@mutex.lock if @multithread
socket.write command
result = socket.gets
raise MemCacheError, $1.strip if result =~ /^SERVER_ERROR (.*)/
rescue SocketError, SystemCallError, IOError => err
server.close
raise MemCacheError, err.message
ensure
@mutex.unlock if @multithread
end
end
******************************************
I found that in some cases socket.write command would throw the
appropriate IOError, but that sometimes it would return OK and result
would be 'nil'

I added this code

if result.nil?
server.close
raise MemCacheError, "No MemCache Server"
end

and that throws my exception, but that seems pretty hackish and I'd
like to get a better understanding of the problem.

What's interesting to me is that it only happens if a set was called
while the memcache server was up, then another called after the server
was stopped. It never happens if the memcache object has never
successfully done a set. Meanwhile, a get will always throw an
exception, though different ones ( connection reset by peer and lost
connection to localhost:11211 ) about equally.

memcache-client 1.5
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin8.11.1]

running on Mac OS 10.4

memcached 1.2.4

Any thoughts are appreciated.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with "ImportError: No module named..." and sockets Daniel Python 4 10-01-2008 05:55 PM
Problem with sockets and python 2.5 Jose Alberto Reguero Python 0 03-19-2007 09:07 PM
How to do INTERESTING things with Ruby sockets??? theosib@gmail.com Ruby 1 03-07-2007 06:05 PM
Help needed in problem with Threads and sockets. Gonšalo Rodrigues Python 0 12-29-2003 07:39 PM
Problem with blocking portably on sockets and Queue? Tero Saarni Python 2 08-07-2003 04:44 AM



Advertisments