rust icon indicating copy to clipboard operation
rust copied to clipboard

Abort read handler when read stream returns EOF

Open powturns opened this issue 1 year ago • 1 comments

If read_stream.read returns 0 bytes read (indicating EOF), return an error to terminate message processing. This prevents the read handler from entering into a tight loop where 0 bytes are read repeatedly.

Currently, if the radio is disconnected (eg: USB unplugged, network error, radio reboot) the read handler spikes cpu usage to 100% on a single core.

Technically, the AsyncReadExt contract does not guarantee that data is never returned after a zero-byte read; however, in practice for the concrete implementations in this library, this is the case.

An alternative implementation could be introducing a short delay after reading 0 bytes, then relying on the heartbeat to detect a disconnected radio. However, the default heartbeat of 5 minutes means there could potentially be a long delay before a disconnect is noticed. This is especially undesirable when using the TCP connection as simply reconnecting to the radio will likely clear the error condition.

Fixes #14

powturns avatar Aug 22 '24 12:08 powturns

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 22 '24 12:08 CLAassistant

Merging, will fix the formatting in a followup commit.

lukipuki avatar Oct 10 '24 05:10 lukipuki