If the instrument sends OK\n but it arrives as two calls such as OK + \n, the b.endswith(b"\n") check on the first chunk misses the line ending. That can leave the function waiting longer than expected or blocking until timeout or socket close.
Fix approach
Accumulate into a bytearray and check the joined buffer for b"\n" instead of only checking the most recent chunk.
Status
Local fix already implemented in the current v0.2 working copy.
Still needs commit, push, and hardware verification before closing.
### Problem
`_recv_line()` can block indefinitely if the newline does not arrive at the end of a single `recv()` chunk.
### Current code
```python
def _recv_line(self) -> str:
chunks = []
while True:
b = self.sock.recv(4096)
if not b:
break
chunks.append(b)
if b.endswith(b"\n"):
break
```
### Why this is a bug
`recv(4096)` can return partial TCP chunks.
If the instrument sends `OK\n` but it arrives as two calls such as `OK` + `\n`, the `b.endswith(b"\n")` check on the first chunk misses the line ending. That can leave the function waiting longer than expected or blocking until timeout or socket close.
### Fix approach
Accumulate into a `bytearray` and check the joined buffer for `b"\n"` instead of only checking the most recent chunk.
### Status
Local fix already implemented in the current v0.2 working copy.
Still needs commit, push, and hardware verification before closing.
tgohle
changed title from _recv_line() can block on partial TCP receive to [Bug]: _recv_line() can block on partial TCP receive2026-04-18 11:22:42 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
_recv_line()can block indefinitely if the newline does not arrive at the end of a singlerecv()chunk.Current code
Why this is a bug
recv(4096)can return partial TCP chunks.If the instrument sends
OK\nbut it arrives as two calls such asOK+\n, theb.endswith(b"\n")check on the first chunk misses the line ending. That can leave the function waiting longer than expected or blocking until timeout or socket close.Fix approach
Accumulate into a
bytearrayand check the joined buffer forb"\n"instead of only checking the most recent chunk.Status
Local fix already implemented in the current v0.2 working copy.
Still needs commit, push, and hardware verification before closing.
_recv_line() can block on partial TCP receiveto [Bug]: _recv_line() can block on partial TCP receive