FreeOpcUa / opcua-asyncio

OPC UA library for python >= 3.7
GNU Lesser General Public License v3.0
1.04k stars 346 forks source link

Discrepancy Between _current_connections and CurrentSessionCount in OPC UA Server Implementation #1569

Closed mloumi closed 4 months ago

mloumi commented 5 months ago

Describe the bug
When initializing an OPC UA server, I observed that the variable _current_connections in internal_session.py accurately tracks the number of clients connected to the server, essentially reflecting the number of open sessions. However, there seems to be a discrepancy with another variable, CurrentSessionCount, located within the ServerDiagnosticsSummaryDataType class. Unlike _current_connections, CurrentSessionCount consistently remains at 0, failing to update as client sessions change. Question: Is it expected behavior for CurrentSessionCount to not mirror the actual number of active sessions, or is this an inconsistency that needs addressing? I would like CurrentSessionCount to reflect the same value as _current_connections. Attempted Workaround: To align the values of these variables, I attempted the following workaround:

## Assuming server has been initialized and configured
 async with server:
        try:
            while True:
                if ServerDiagnosticsSummaryDataType.CurrentSessionCount != server.iserver.isession._current_connections:
                    ServerDiagnosticsSummaryDataType.CurrentSessionCount = server.iserver.isession._current_connections                
                await asyncio.sleep(1)

To Reproduce

  1. Check the value of CurrentSessionCount using a print statement:
    from asyncua.ua.uaprotocol_auto import ServerDiagnosticsSummaryDataType 
    print(ServerDiagnosticsSummaryDataType.CurrentSessionCount) 
  2. Connect multiple clients to the server.
  3. Observe that the value of CurrentSessionCount remains unchanged despite the varying number of connections.

Expected behavior
I expect the CurrentSessionCount variable to accurately reflect the real-time number of current sessions, rather than remaining static at 0.

Version
Python-Version: 3.11 opcua-asyncio Version: 1.0.6

AndreasHeine commented 4 months ago

Server diagnostics are not implemented yet!