forked from M-Labs/artiq
1
0
Fork 0

coredevice: Handle prematurely closed sockets in comm_kernel receive loop

recv() returns 0 instead of data if the socket has already
been closed. This is translated into a zero-length list on
the Python layer. Previously, the code would enter an
infinite loop if the socket was closed while attempting
to receive data.
This commit is contained in:
David Nadlinger 2021-01-22 19:13:42 +01:00 committed by Sébastien Bourdeauducq
parent f1fd42ea98
commit f9872bb7b8
1 changed files with 4 additions and 1 deletions

View File

@ -223,7 +223,10 @@ class CommKernel:
flag = 0 flag = 0
if diff > 8192: if diff > 8192:
flag |= socket.MSG_WAITALL flag |= socket.MSG_WAITALL
self.read_buffer += self.socket.recv(8192, flag) new_buffer = self.socket.recv(8192, flag)
if not new_buffer:
raise ConnectionResetError("Core device connection closed unexpectedly")
self.read_buffer += new_buffer
result = self.read_buffer[:length] result = self.read_buffer[:length]
self.read_buffer = self.read_buffer[length:] self.read_buffer = self.read_buffer[length:]
return result return result