Koheron / koheron-sdk

SDK for FPGA / Linux Instruments
https://www.koheron.com/software-development-kit/
Other
101 stars 41 forks source link

Python: Correctly detect socket closure, don't return partial data #601

Closed chrisjbillington closed 5 months ago

chrisjbillington commented 5 months ago

if chunk == '': did not detect socket closure correctly, because chunk is a bytestring and b'' == '' is False. On socket closure by the server, recv_all() would get stuck in a busy loop and consume memory without limit. Check if not chunk: instead.

In addition, raise an exception instead of returning partial data. Partial data is not useful to the caller, in the case of unexpected remote socket closure, better to raise an exception immediately than wait for calling code to raise exceptions about not being able to parse the partial data.