Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working with memcached #34

Closed
pegler opened this issue Feb 19, 2013 · 2 comments
Closed

not working with memcached #34

pegler opened this issue Feb 19, 2013 · 2 comments

Comments

@pegler
Copy link

pegler commented Feb 19, 2013

HTTPretty causes requests to memcached to hang indefinitely when using Django.

Implementing the change here: https://github.com/nicolas-DH/HTTPretty/commit/dc622c8027a778ea4a385bf08af9ee751a189765 fixes the hanging problem, but then interaction with memcached is broken. Requests to insert keys do not succeed. I assume this is due to how _true_sendall works, but I am not sure.

Let me know how I can debug further.

@pegler
Copy link
Author

pegler commented Feb 20, 2013

Like I said earlier, with an unmodified version of HTTPretty, it hangs in the _true_sendall method. By modifying it to be as follows, the method returns:

        def _true_sendall(self, data, *args, **kw):
            self.truesock.connect(self._address)
            self.truesock.sendall(data, *args, **kw)
            _d = self.truesock.recv(16)
            self.fd.seek(0)
            self.fd.write(_d)
            while _d:
                if len(_d) < 16:
                    break
                _d = self.truesock.recv(16)
                self.fd.write(_d)

            self.fd.seek(0)
            self.truesock.close()

After disabling cached sessions in my django settings, I received this trace from the HTTPretty debug method when trying to access memcached while HTTPretty is enabled. memcache.py is http://pypi.python.org/pypi/python-memcached/

...
  File "/home/pegler/environments/site/local/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 53, in add
    return self._cache.add(key, value, self._get_memcache_timeout(timeout))
  File "/home/pegler/environments/site/local/lib/python2.7/site-packages/memcache.py", line 506, in add
    return self._set("add", key, val, time, min_compress_len)
  File "/home/pegler/environments/site/local/lib/python2.7/site-packages/memcache.py", line 802, in _set
    return _unsafe_set()
  File "/home/pegler/environments/site/local/lib/python2.7/site-packages/memcache.py", line 795, in _unsafe_set
    return(server.expect("STORED") == "STORED")
  File "/home/pegler/environments/site/local/lib/python2.7/site-packages/memcache.py", line 1136, in expect
    line = self.readline()
  File "/home/pegler/environments/site/local/lib/python2.7/site-packages/memcache.py", line 1125, in readline
    data = recv(4096)
  File "/home/pegler/environments/site/src/httpretty/httpretty/__init__.py", line 319, in debug
    lines = map(utf8, traceback.format_stack(frame))

@stephenemslie
Copy link

I'm seeing the same behaviour with pymongo. In my case it's blocking on _d = self.truesock.recv(16) inside the while loop. Presumably this is down to the Mongo wire protocol not returning anything at that point, and there doesn't appear to be a timeout on the socket.

ipdb> print self.truesock.gettimeout()
None

A workaround is to set a timeout on self.truesock.

ipdb> self.truesock.settimeout(1)
ipdb> self.truesock.recv(16)
*** timeout: timed out

Or globally in your tests:

import socket
socket.setdefaulttimeout(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants