pazzarpj / aiomodbus

Asyncio Library for Modbus
MIT License
5 stars 1 forks source link

Invalid state error when cancelling tasks #39

Open pazzarpj opened 1 year ago

pazzarpj commented 1 year ago
def from_func_code(fut, func_code, data):
    if func_code & 0x80:
        fut.set_exception(modbus_exception_codes[data[0]])
    else:
        try:
            fut.set_result(function_codes[func_code](data))
        except BaseException as e:
            fut.set_exception(e)

Here we set a future without checking if the future is done. This can cause an invalid state error when a task is cancelled before processing a response