hardbyte / hardbyte/python-can

SocketcanBus.send() timeout semantics differ from BusABC.send()

未關閉
#2,005 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Python
星號
1.6k
分支
697
PR 合併指標
30 天內沒有已合併 PR

描述

### Describe the bug
In the `send()` method of `BusABC`, the optional `timeout` argument is documented as
```
If > 0, wait up to this many seconds for message to be ACK'ed or
for transmit queue to be ready depending on driver implementation.
If timeout is exceeded, an exception will be raised.
Might not be supported by all interfaces.
None blocks indefinitely.
```

but the `SocketcanBus` implementation of `BusABC` documents (and implements) it like this:
```
Wait up to this many seconds for the transmit queue to be ready.
If not given, the call may fail immediately.
```

It looks to me like the handling in `SocketcanBus` just doesn't conform to the expected interface, in particular it does
```python
# If no timeout is given, poll for availability
if timeout is None:
timeout = 0
```
which results in nonblocking behavior and potentially raising `can.CanOperationError("Transmit buffer full")` instead of waiting indefinitely when no timeout is specified.

### To Reproduce
```python
msg = can.Message(
arbitration_id=0x123, is_extended_id=False, data=[1, 2, 3, 4, 5, 6, 7, 8]
)
with can.Bus(interface="socketcan", channel="can0") as bus:
for i in range(10000):
bus.send(msg)
```
Observe that sending fails if the sending rate exceeds the capacity of the bus, instead of blocking and waiting.

### Expected behavior
As the timeout is `None`, blocking indefinitely until the transmit queue is ready, as specified in the `BusABC.send()` docs.

### Additional context

OS and version: Ubuntu 24.04.3 LTS, 6.14.0-35-generic
Python version: Python 3.12.3
python-can version: 4.3.1
python-can interface/s (if applicable): socketcan, F81601 interface (PCI), Manufacturer provided driver

貢獻指南

開啟貢獻指南

研究方向

Start by comparing the SocketcanBus.send() implementation with the BusABC.send() documentation and behavior, then reproduce the queue-full case described with the provided send loop. Done means a missing timeout follows the documented blocking semantics, while explicit timeouts retain their stated behavior; add or update coverage for these cases if the existing test locations are found.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
linux, python
領域
embedded-iot, networking
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。