Skip to content

Commit 87e9253

Browse files
kesmit13claude
andcommitted
Restore socket timeout after partial-read recovery in _recv_exact_py
When a TimeoutError occurs mid-message, the function removes the socket timeout to avoid protocol desync. Previously the timeout was never restored, causing the caller's shutdown-polling loop to block indefinitely on subsequent reads. Now the original timeout is saved and restored on both EOF and successful completion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4c7fb60 commit 87e9253

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

singlestoredb/functions/ext/collocated/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def _recv_exact_py(sock: socket.socket, n: int) -> bytes | None:
394394
buf = bytearray(n)
395395
view = memoryview(buf)
396396
pos = 0
397+
orig_timeout = sock.gettimeout()
397398
while pos < n:
398399
try:
399400
nbytes = sock.recv_into(view[pos:])
@@ -405,8 +406,12 @@ def _recv_exact_py(sock: socket.socket, n: int) -> bytes | None:
405406
sock.settimeout(None)
406407
continue
407408
if nbytes == 0:
409+
if orig_timeout is not None:
410+
sock.settimeout(orig_timeout)
408411
return None
409412
pos += nbytes
413+
if orig_timeout is not None:
414+
sock.settimeout(orig_timeout)
410415
return bytes(buf)
411416

412417

0 commit comments

Comments
 (0)