Description
OS: macOS
pymodbus version 3.9.2
I supply the following dummy hook to the trace_connect
argument during ModbusTcpServer
instantiation:
def print_connect(connected):
print("CONNECT:", connected)
Observed behaviour
Upon client connection (and subsequent disconnection), I get the following debug print on my console:
(venv) $ python ./server.py
CONNECT: True
CONNECT: True
CONNECT: False
Apparently, the callback is invoked twice upon connect, and once upon disconnect.
Expected behaviour
I would expect only a single callback invocation upon connect:
(venv) $ python ./server.py
CONNECT: True
CONNECT: False
Debugging
A quick, narrowed down, Git grep reveals the following invocations:
$ git grep -n 'self\.trace_connect('
pymodbus/server/base.py:64: self.trace_connect(True)
pymodbus/transaction/transaction.py:205: self.trace_connect(True)
pymodbus/transaction/transaction.py:209: self.trace_connect(False)
It seems to me the invocation in server/base.py
is superfluous, and should possibly be removed (?). OTOH, changing the behaviour would be a breaking change. OTOH again, this API is not exactly very well documented.
The superfluous invocation was added by @janiversen in commit bebccce, PR #2549, issue #2546.