You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Django unit tests hang forever when redis is not reachable #630
When my redis instance is not reachable, it seems that my unit tests hang indefinitely. No single test is executed, though, just a hang after the system checks.
I have tried setting the timeouts, socket timeouts, etc, without any luck.
Is there some way to get this to fail faster, is there something I am configuring incorrectly?
project ❯ ./manage.py test
Found 262 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
# <hangs here>
# ^C^C to exit
Not sure how you tracked yours down, but so far mine doesn't seem the same. I stuck a couple print()s around there and saw nothing.
Maybe I've posted this in the wrong place. At the time I thought it was right, though, but now it seems like I have even less clue. RQ? core redis?
In my case it doesn't even seem to start the testing, and the stack trace when I kill the process is always stuck here:
python3.11/site-packages/rq/job.py", line 696, in save
if self.get_redis_server_version() >= (4, 0, 0):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
python3.11/site-packages/rq/utils.py", line 281, in get_version
return tuple(int(i) for i in connection.info("server")["redis_version"].split('.')[:3])
...
python3.11/site-packages//rq_scheduler/scheduler.py", line 246, in schedule
job.save()
...
python3.11/site-packages/redis/connection.py", line 734, in on_connect
if str_if_bytes(self.read_response()) != "OK":
^^^^^^^^^^^^^^^^^^^^
...
python3.11/site-packages/redis/connection.py", line 318, in read_response
raw = self._buffer.readline()
^^^^^^^^^^^^^^^^^^^^^^^
python3.11/site-packages/redis/connection.py", line 249, in readline
self._read_from_socket()
python3.11/site-packages/redis/connection.py", line 192, in _read_from_socket
data = self._sock.recv(socket_read_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
My tone comes off way wrong on that one, what I meant was: "I don't know how you tracked that down, amazing work. I read the code and didn't see anything wrong, hats off to you!"
This is definitely posted in the wrong place, it should be in redis or in rq/rq_scheduler if not. Hang is also on runserver and not just test
Not sure what else to do to track this down, other than move the issue over there. I'll close this one. For posterity:
Retested on 3.10 with fully upgraded redis/rq/etc and the same issue at the same point (with different surrounding code). The hang is in redis.py itself, but probably originates somewhere else like with a misconfigured client.
connection.connect() hangs for at least >5 minutes
def get_version(connection: 'Redis'):
try:
# ... cache it on the connection object
if not getattr(connection, "__rq_redis_server_version", None):
setattr(
connection,
"__rq_redis_server_version",
# <<<
# <<< ------------ hang in connection.info() --------------
# <<<
tuple(int(i) for i in connection.info("server")["redis_version"].split('.')[:3])
)
return getattr(connection, "__rq_redis_server_version")
except ResponseError: # fakeredis doesn't implement Redis' INFO command
return (5, 0, 9)
rq_scheduler/scheduler.py@246, schedule(): job.save()
rq/job.py@759, save(): if self.get_redis_server_version()...
rq/job.py@722, get_redis_server_version(): ... = get_version(self.connection)
rq/utils.py@311, get_version(): ... connection.info("server")...
redis/commands/core.py@982, info(): self.execute_command("INFO", ...
redis/client.py@1255, execute_command(): conn = self.connection or pool.get_...
redis/connection.py@1427, get_connection(): connection.connect()
redis/connection.py@636, connect(): self.on_connect()
redis/connection.py@759, on_connect(): if str_if_bytes(self.read_response()) != "OK":
redis/connection.py@848, read_response(): response = self._parser.read_response(...
redis/connection.py@335, read_response(): self._read_response(...)
redis/connection.py@344, _read_response(): raw = self._buffer.readline()
redis/connection.py@243, readline(): self._read_from_socket()
redis/connection.py", line 192, in _read_from_socket
data = self._sock.recv(socket_read_size)
# infinite hang here
Activity
adamkal commentedon Jan 25, 2023
I have the same issue. I found an infinite loop in the
TestCase._clean_tracebacksIn my case this is the way
excschanges with each loop:Seems to me that the problem is in this line in
omit_exception.I noticed that the algorithm for cleaning is fairly fresh which might be the trigger of the issue
awbacker commentedon Jan 25, 2023
Not sure how you tracked yours down, but so far mine doesn't seem the same. I stuck a couple
print()s around there and saw nothing.Maybe I've posted this in the wrong place. At the time I thought it was right, though, but now it seems like I have even less clue. RQ? core redis?
In my case it doesn't even seem to start the testing, and the stack trace when I kill the process is always stuck here:
adamkal commentedon Jan 26, 2023
Indeed. I definitely get an connection exception that goes further into tests and get's stuck later, when collecting traceback.
Might be worth mentioning I'm working on Python 3.9
awbacker commentedon Jan 26, 2023
My tone comes off way wrong on that one, what I meant was: "I don't know how you tracked that down, amazing work. I read the code and didn't see anything wrong, hats off to you!"
This is definitely posted in the wrong place, it should be in
redisor inrq/rq_schedulerif not. Hang is also onrunserverand not justtestNot sure what else to do to track this down, other than move the issue over there. I'll close this one. For posterity:
Retested on 3.10 with fully upgraded redis/rq/etc and the same issue at the same point (with different surrounding code). The hang is in redis.py itself, but probably originates somewhere else like with a misconfigured client.
connection.connect()hangs for at least >5 minuteshttps://github.com/rq/rq/blob/master/rq/utils.py#L325
awbacker commentedon Jan 26, 2023
This issue is not the result of django-redis, as far as I can tell. Reopen if you find a link.
awbacker commentedon Jan 26, 2023
I see this now, too, it was covered up before by the other library failing first!
rq_schedulerandjob.save()infinite hang onrecvfirstThanks!