Skip to content

trace_connect is called twice #2669

Closed
@erlend-aasland

Description

@erlend-aasland

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions