Skip to content

Commit 925c610

Browse files
authored
Tidying of OpenSSL 1.0.2/Python 3.9 (and earlier) handling (#5854)
1 parent 60ce843 commit 925c610

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

distributed/comm/tcp.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@
4343
logger = logging.getLogger(__name__)
4444

4545

46-
C_INT_MAX = 256 ** ctypes.sizeof(ctypes.c_int) // 2 - 1
46+
# Workaround for OpenSSL 1.0.2.
47+
# Can drop with OpenSSL 1.1.1 used by Python 3.10+.
48+
# ref: https://bugs.python.org/issue42853
49+
if sys.version_info < (3, 10):
50+
OPENSSL_MAX_CHUNKSIZE = 256 ** ctypes.sizeof(ctypes.c_int) // 2 - 1
51+
else:
52+
OPENSSL_MAX_CHUNKSIZE = 256 ** ctypes.sizeof(ctypes.c_size_t) - 1
53+
4754
MAX_BUFFER_SIZE = MEMORY_LIMIT / 2
4855

4956

@@ -212,9 +219,9 @@ async def read(self, deserializers=None):
212219
(frames_nbytes,) = struct.unpack(fmt, frames_nbytes)
213220

214221
frames = host_array(frames_nbytes)
215-
# Workaround for OpenSSL 1.0.2 (can drop with OpenSSL 1.1.1)
216222
for i, j in sliding_window(
217-
2, range(0, frames_nbytes + C_INT_MAX, C_INT_MAX)
223+
2,
224+
range(0, frames_nbytes + OPENSSL_MAX_CHUNKSIZE, OPENSSL_MAX_CHUNKSIZE),
218225
):
219226
chunk = frames[i:j]
220227
chunk_nbytes = len(chunk)
@@ -351,8 +358,7 @@ class TLS(TCP):
351358
A TLS-specific version of TCP.
352359
"""
353360

354-
# Workaround for OpenSSL 1.0.2 (can drop with OpenSSL 1.1.1)
355-
max_shard_size = min(C_INT_MAX, TCP.max_shard_size)
361+
max_shard_size = min(OPENSSL_MAX_CHUNKSIZE, TCP.max_shard_size)
356362

357363
def _read_extra(self):
358364
TCP._read_extra(self)

0 commit comments

Comments
 (0)