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

'NoneType' object has no attribute 'recv' #612

Open
BertrandBordage opened this issue Sep 26, 2024 · 0 comments
Open

'NoneType' object has no attribute 'recv' #612

BertrandBordage opened this issue Sep 26, 2024 · 0 comments

Comments

@BertrandBordage
Copy link

BertrandBordage commented Sep 26, 2024

This error happens occasionally at random in my application.
The application:

  • uses gunicorn --workers 1 --threads 8, so with gthread
  • connects to memcached through a UNIX socket
  • the application and memcached run in separate Docker Compose services, with the UNIX socket being shared through a named volume

Cache configuration in Django:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
        'LOCATION': 'unix:/var/run/memcached/memcached.sock',
        'OPTIONS': {
            'use_pooling': True,  # Keeps connections alive, more reliable with multiple threads per worker.
            'default_noreply': True,  # Do not wait for a reply when we do not need it.
            'connect_timeout': 10.0,  # seconds
            'timeout': 10.0,  # seconds
        },
    },
}

'ignore_exc': True could be specified to consider this error a cache miss (if this type of error is correctly caught), but this means we would not know whether 1% or 100% of the cache calls are failing.

Versions:
pymemcache 4.0.0
memcached 1.6.31 (from the memcached:1.6.31-alpine Docker image)
gunicorn 23.0.0
Python 3.12.4
Django 5.0.7

Relevant traceback:

  File "/srv/.local/lib/python3.12/site-packages/django/core/cache/backends/memcached.py", line 75, in get
    return self._cache.get(key, default)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/hash.py", line 347, in get
    return self._run_cmd("get", key, default, default=default, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/hash.py", line 322, in _run_cmd
    return self._safely_run_func(client, func, default_val, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/hash.py", line 211, in _safely_run_func
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/base.py", line 1494, in get
    return client.get(key, default)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/base.py", line 687, in get
    return self._fetch_cmd(b"get", [key], False, key_prefix=self.key_prefix).get(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/base.py", line 1145, in _fetch_cmd
    buf, line = _readline(self.sock, buf)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/base.py", line 1658, in _readline
    buf = _recv(sock, RECV_SIZE)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/.local/lib/python3.12/site-packages/pymemcache/client/base.py", line 1750, in _recv
    return sock.recv(size)
           ^^^^^^^^^

EDIT: The memcached server was up and running at that time. docker compose ps considered it healthy for the entire day this issue happened.

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

1 participant