Interesting problem with memcache-client and sockets

Discussion in 'Ruby' started by Jakanapes, Feb 8, 2008.

  1. Jakanapes

    Jakanapes Guest

    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.
    Jakanapes, Feb 8, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hemant kumar

    regarding memcache client...

    hemant kumar, Aug 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    107
    Eric Hodel
    Aug 31, 2006
  2. hemant

    Using Memcache client

    hemant, Sep 20, 2006, in forum: Ruby
    Replies:
    1
    Views:
    110
    Eric Hodel
    Sep 21, 2006
  3. Eric Hodel
    Replies:
    0
    Views:
    88
    Eric Hodel
    Oct 18, 2006
  4. Eric Hodel
    Replies:
    0
    Views:
    97
    Eric Hodel
    Dec 7, 2006
  5. Eric Hodel
    Replies:
    0
    Views:
    84
    Eric Hodel
    Mar 7, 2007
Loading...

Share This Page