pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.16k stars 889 forks source link

TCP client frame mismatch under heavy load #2173

Closed martyy665 closed 2 months ago

martyy665 commented 2 months ago

Versions

Pymodbus Specific

Description

After some periodic readouts from multiple slaves, wrong data are returned (data coming from another slave). It appears when the tid counter overflows 65535 and goes back to zero. Changing the line 507 in pymodbus/transaction.py below fixes the issue.

Code and Logs


     def getTransaction(self, tid):
499         """Return a transaction matching the referenced tid.
500
501         If the transaction does not exist, None is returned
502
503         :param tid: The transaction to retrieve
504
505         """
506         Log.debug("Getting transaction {}", tid)
507         if tid is None:
508             if self.transactions:
509                 return self.transactions.popitem()[1]
510             return None
511         return self.transactions.pop(tid, None)
janiversen commented 2 months ago

Please submit a pull request.

It is an interesting observation, we do not have a test case for this.

martyy665 commented 2 months ago

Solved in approved PR.

janiversen commented 2 months ago

It seems I slept when approving this, because it breaks a lot of tests. Problem is that tid == 0 is an allowed transaction,

Will submit a fix shortly,