Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pymodbus 3.4.0, bug in async_execute #1702

Closed
tomas-bozek opened this issue Jul 26, 2023 · 5 comments · Fixed by #1729
Closed

Pymodbus 3.4.0, bug in async_execute #1702

tomas-bozek opened this issue Jul 26, 2023 · 5 comments · Fixed by #1729
Assignees

Comments

@tomas-bozek
Copy link

Python: 3.8
Pymodbus: 3.4.0
used on: UDP Client (for our example connection to nowhere, or not existed address)

Bug:
https://github.com/pymodbus-dev/pymodbus/blob/dev/pymodbus/client/base.py#L193
Future is created only ONCE

code tries to use retries, first time it is ok, when more times then wait_for using CANCELLED future!

FIX:
move req = self._build_response(request.transaction_id) to wait_for

async def async_execute(self, request=None):
        """Execute requests asynchronously."""
        request.transaction_id = self.transaction.getNextTID()
        packet = self.framer.buildPacket(request)
        self.transport_send(packet)        
        if self.params.broadcast_enable and not request.slave_id:
            resp = b"Broadcast write sent - no response expected"
        else:
            count = 0
            while count < self.params.retries:
                count += 1
                try:
                    req = self._build_response(request.transaction_id)
                    resp = await asyncio.wait_for(
                        req, timeout=self.comm_params.timeout_connect
                    )
                    break
                except asyncio.exceptions.TimeoutError:
                    pass
            if count == self.params.retries:
                self.close(reconnect=True)
                raise ModbusIOException(
                    f"ERROR: No response received after {self.params.retries} retries"
                )
        return resp
@janiversen
Copy link
Collaborator

Pull requests are welcome.

@janiversen
Copy link
Collaborator

janiversen commented Jul 26, 2023

v3.4.1 will be released this weekend, so that is the deadline for a PR, that is if you want it in the next release cycle.

@tomas-bozek
Copy link
Author

v3.4.1 will be released this weekend, so that is the deadline for a PR, that is if you want it in the next release cycle.

I'm on vacation. i shall do it, but after vacation.

@janiversen
Copy link
Collaborator

Have a nice vacation.

@tomas-bozek
Copy link
Author

Have a nice vacation.

thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants