Skip to content

TCP backend should handle out of order responses #255

@pdegoeje

Description

@pdegoeje

A libmodbus client can become stuck reading what it thinks are invalid responses (wrong transaction ID), while only one (the first) response is delayed beyond the timeout.

client: modbus_read_registers (tid = 1) -> ETIMEDOUT
client: modbus_read_registers (tid = 2)
server: send tid = 1 response
client: tid mismatch -> EBADDATA
client: modbus_read_registers (tid = 3)
server: send tid = 2 response
client: tid mismatch -> EBADDATA
client: modbus_read_registers (tid = 4)
server: send tid = 3 response
client: tid mismatch -> EBADDATA
etc.

The assumption that all responses are in order is incorrect, even if only a single thread is responsible for I/O.

A more robust way of handling this would be to discard responses where the TID doesn't match the request and wait for the correct response to arrive or for the timeout to occur, whichever happens first.

Ideally there would be an asynchronous API so multiple request/responses can be in-flight at any time, but that would be quite a bit of additional work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions