Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Async Serial Client Can't Recover from task cancellations #360

@pazzarpj

Description

@pazzarpj

Versions

  • Python: 3.5
  • OS: Windows/Linux
  • Pymodbus: 2.1
  • Modbus Hardware (if used): Serial loopback

Pymodbus Specific

  • Client: rtu - async

Description

I encountered this issue when trying to read asynchronously after performing a task.cancel on an awaited read.

import async_timeout
with async_timeout.timeout(1) as cm:
    await client.protocol.read_holding_registers(0, 1)

If the timeout is allowed to kick in (ie. the read takes longer than 1 second, by not having server running or something) , you have a cancelled task that isn't cleaned up by the transaction handler.
In the socket based systems this is fine as the transaction ID is explicitly retrieved via dictionary call but in the FifoTransactionManager, you now have a lurking cancelled task that is returned next time we call to the client. Eg.
multiple transactions failure

So the next time we

await client.protocol.read_holding_registers(0,1)

We are going to be getting the cancelled future from the transaction manager when we call getTransaction(). This means that the await task is never woken up and you have crashed it until task.cancel() is called, which will mean that next time it is called there is another cancelled future waiting to be returned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions