FluentModbus icon indicating copy to clipboard operation
FluentModbus copied to clipboard

[Issue] Potential forever loop during receive (in both sync and async API version)

Open horeich opened this issue 2 years ago • 0 comments

Hi,

is there a reason, why we read the incoming frame in a while loop? Looks potentially dangerous to me.

while (true)

Why do we not simply define a serial timeout which defines the "receive window" and simply wait for a timeout or invalid data (which is accounted for by ModbusUtils.DetectFrame)? Per definition a Modbus frame should arrive as a continuous block (please correct me if I'm wrong).

Currently the implementation may get stuck in the while loop if we receive a continuous data stream via the serial port which is not detected as a valid frame (as the buffer will be reset if it is full). At least, we should handle a full frame buffer differently.

Same applies to the async version.

horeich avatar Sep 12 '22 21:09 horeich