Whole file

redis/redis-py

The author described this change as Fix hiredis readiness checks for high file descriptors (#4115). It counts as a record because the checks below fail on the code as it stood at 640f0d055 and pass on 2febde067, with nothing else changed between the two runs.

Fix saved2026-06-11
Sharing licenceMIT · LICENSE
Change size+6 2

What the code was meant to do, written into the code itself as a save note

Fix hiredis readiness checks for high file descriptors (#4115)

The change

1-import select
1+import selectors
22 import socket
33 from logging import getLogger
44 from typing import Callable, List, Optional, TypedDict, Union
2828 # SSL sockets can have decrypted bytes buffered above the OS socket layer.
2929 if hasattr(sock, "pending") and sock.pending():
3030 return True
31- return bool(select.select([sock], [], [], timeout)[0])
31+ # timeout=0 must be a non-blocking readiness check only. The selector keeps
32+ # this non-destructive while avoiding select.select's low fd limit on Unix.
33+ with selectors.DefaultSelector() as selector:
34+ selector.register(sock, selectors.EVENT_READ)
35+ return bool(selector.select(timeout))
3236
3337
3438 class _HiredisReaderArgs(TypedDict, total=False):

The check that tells the two apart

failpass·tests/test_connection.py::test_hiredis_socket_can_read_handles_high_file_descriptor
failpass·tests/test_connection.py::test_hiredis_socket_can_read_uses_default_selector

Check file tests/test_connection.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it640f0d055f19a9203cc894998d97150676dbf947
Broken version dated2026-06-10
Moduleredis._parsers.hiredis
Units changed_socket_can_read
Fingerprint10a55e1d70179eda
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in redis/redis-py