WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

The backend code is not thread-safe, leads to network errors when running from multi-threaded gunicorn etc. #626

@aivarsk

Description

@aivarsk

For example, getting a value:

result = self._backend.get(key)

Goes to the backend:

value = self._rd.get(self.add_prefix(key))

And there it uses the global Redis connection (self._rd) without locking it.

Which probably relates to this setting in Redis client
https://github.com/redis/redis-py/blob/master/redis/client.py#L271 and then the code fails on the retries when one thread closes the connection and the other tries to use it around here https://github.com/redis/redis-py/blob/master/redis/client.py#L638

Unfortunately I no longer have the stack traces in the slack history. We ended up always using a single-threaded WSGI runner.

I think the correct way is to lock the backend before using it, I have not checked the thread-safety guarantees by RedisPy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions