Closed tsionyx closed 5 years ago
I guess we could switch to asci ids? Base64 encoded perhaps. How about that?
I think it could help
3.2 actual:
File "/usr/lib/python3/dist-packages/redis_lock/__init__.py", line 322, in __enter__
acquired = self.acquire(blocking=True)
File "/usr/lib/python3/dist-packages/redis_lock/__init__.py", line 211, in acquire
if self._held:
File "/usr/lib/python3/dist-packages/redis_lock/__init__.py", line 186, in _held
return self.id == self.get_owner_id()
File "/usr/lib/python3/dist-packages/redis_lock/__init__.py", line 200, in get_owner_id
return self._client.get(self._name)
File "/usr/lib/python3/dist-packages/redis/client.py", line 880, in get
return self.execute_command('GET', name)
File "/usr/lib/python3/dist-packages/redis/client.py", line 573, in execute_command
return self.parse_response(connection, command_name, **options)
File "/usr/lib/python3/dist-packages/redis/client.py", line 585, in parse_response
response = connection.read_response()
File "/usr/lib/python3/dist-packages/redis/connection.py", line 577, in read_response
response = self._parser.read_response()
File "/usr/lib/python3/dist-packages/redis/connection.py", line 280, in read_response
response = response.decode(self.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 1: invalid start byte
Not contributing anything to the conversation here aside to vote for a fix. 👍
Updated the Redis session for our locks to decode_response=False
... which was an easy enough fix for now, but it'd be nice if we didn't have to do that as we obviously can't reuse our Redis session objects anymore for other interfaces that rely on the decoding functionality.
Oh... also here's a 3.6 stack for what it's worth:
File "./test.py", line 822, in test
if lock.acquire(blocking=False):
File "/x/test/env/live/lib/python3.6/site-packages/redis_lock/__init__.py", line 211, in acquire
if self._held:
File "/x/test/env/live/lib/python3.6/site-packages/redis_lock/__init__.py", line 186, in _held
return self.id == self.get_owner_id()
File "/x/test/env/live/lib/python3.6/site-packages/redis_lock/__init__.py", line 200, in get_owner_id
return self._client.get(self._name)
File "/x/test/env/live/lib/python3.6/site-packages/redis/client.py", line 976, in get
return self.execute_command('GET', name)
File "/x/test/env/live/lib/python3.6/site-packages/redis/client.py", line 668, in execute_command
return self.parse_response(connection, command_name, **options)
File "/x/test/env/live/lib/python3.6/site-packages/redis/client.py", line 680, in parse_response
response = connection.read_response()
File "/x/test/env/live/lib/python3.6/site-packages/redis/connection.py", line 624, in read_response
response = self._parser.read_response()
File "/x/test/env/live/lib/python3.6/site-packages/redis/connection.py", line 326, in read_response
response = self.encoder.decode(response)
File "/x/test/env/live/lib/python3.6/site-packages/redis/connection.py", line 125, in decode
value = value.decode(self.encoding, self.encoding_errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 0: invalid start byte
+1, seems simple enough to use uuid.uuid4()
instead of urandom(16)
for ASCII IDs. You could always encode
them if you wish them to remain as bytes
objects.
When I creating a
StrictRedis
instance I always set the additional parameterdecode_responses=True
. However the lock is unusable with this setting because of manipulating with raw bytesself.id
variable. As a result I get the following error:Tested on Ubuntu 16.04 LTS, Python 2.7.12 and Python 3.5.2. Removing the
decode_responses
eliminates the problem.