Skip to content

Memory Leakage in the OpenOpcService #73

@aerosadegh

Description

@aerosadegh

Describe the bug I am experiencing two significant issues when using OpenOPC2 for high-frequency OPC DA tag reads:

Slow Reading: Despite attempting to read tags every 300ms, the OpenOpcCli.exe consistently reports that the "Command exceeded interval by" a significant margin (e.g., 1281ms, 1344ms). This indicates that the actual read frequency is much lower than intended.

Memory Leakage: The OpenOpcService.exe process on the server side exhibits a continuous increase in memory consumption. It starts around 17 MB, gradually climbs to 40 MB, and eventually becomes unresponsive to CLI commands. This suggests a memory leak within the service.

To Reproduce
Steps to reproduce the behavior:

Server Setup:

On a Windows 10 22H2 machine, run OpenOpcService.exe. This executable was recompiled (in a poetry venv based on pyproject.toml) with PyInstaller using Python 3.11 x86 for some issues in reading the env.

Ensure Matrikon OPC Simulation Server is running and accessible on the server machine.

Client Setup:

On both Windows machine, set the following environment variables:

env.ps1

$env:OPC_CLASS="Graybox.OPC.DAWrapper"
$env:OPC_CLIENT="OpenOPC"
$env:OPC_GATE_HOST="192.168.1.41"    # Replace with your server's IP address
$env:OPC_GATE_PORT="7766"
$env:OPC_HOST="localhost"
$env:OPC_MODE="dcom"
$env:OPC_SERVER="Matrikon.OPC.Simulation.1"

Reproduce the Bug:

Execute the following command in a PowerShell or Command Prompt window to attempt high-frequency reads:

.\OpenOpcCli.exe read Random.Int1 Random.Int2 Random.Int4 Random.Int8 Random.Real4 Random.Real8 Random.UInt4 Random.UInt8 test --source device --output-csv

Observe the "Command exceeded interval" messages in the client's output.

Monitor the memory usage of OpenOpcService.exe on the server machine using Task Manager.

Environment:

Server OS: Windows 10 22H2

OPC Server: Matrikon OPC Simulation Server

OpenOPC2 Service Compilation: OpenOpcService.exe recompiled with PyInstaller in Python 3.11 x86.

Can you reproduce the Bug with the Matrikon Simulation server in normal OPC Mode without the Gateway?
No, the bug does not occur when connecting directly without the gateway.

Paste your environment variables of the Openopc2
env.ps1

$env:OPC_CLASS="Graybox.OPC.DAWrapper"
$env:OPC_CLIENT="OpenOPC"
$env:OPC_GATE_HOST="192.168.1.41"
$env:OPC_GATE_PORT="7766"
$env:OPC_HOST="localhost"
$env:OPC_MODE="dcom"
$env:OPC_SERVER="Matrikon.OPC.Simulation.1"

Expected behavior

The OpenOpcCli.exe should be able to read tags at or very close to the specified 300ms interval, without consistently exceeding the interval by a large margin.

The OpenOpcService.exe process should maintain a stable memory footprint, or at least release memory after operations, and remain responsive over extended periods of high-frequency data access.

Screenshots(as Text)

Every 300ms: .\OpenOpcCli.exe read Random.Int1 Random.Int2 Random.Int4 Random.Int8 Random.Real4 Random.Real8 Random.UInt4 Random.UInt8 test --source device --output-csv
07/01/2025 13:51:49

Random.Int1,52,Good,2025-07-01 10:22:59.065000+00:00
Random.Int2,9143,Good,2025-07-01 10:22:59.065000+00:00
Random.Int4,4807,Good,2025-07-01 10:22:59.065000+00:00
Random.Int8,32035.0,Good,2025-07-01 10:22:59.065000+00:00
Random.Real4,179.78399658203125,Good,2025-07-01 10:22:59.065000+00:00
Random.Real8,6386.162377770001,Good,2025-07-01 10:22:59.065000+00:00
Random.UInt4,9142.0,Good,2025-07-01 10:22:59.065000+00:00
Random.UInt8,25452.0,Good,2025-07-01 10:22:59.065000+00:00
test,None,Error,None
Command exceeded interval by 1281ms
Every 300ms: .\OpenOpcCli.exe read Random.Int1 Random.Int2 Random.Int4 Random.Int8 Random.Real4 Random.Real8 Random.UInt4 Random.UInt8 test --source device --output-csv
07/01/2025 13:51:50

Random.Int1,57,Good,2025-07-01 10:23:00.713000+00:00
Random.Int2,9478,Good,2025-07-01 10:23:00.713000+00:00
Random.Int4,23225,Good,2025-07-01 10:23:00.713000+00:00
Random.Int8,19496.0,Good,2025-07-01 10:23:00.713000+00:00
Random.Real4,26713.451171875,Good,2025-07-01 10:23:00.713000+00:00
Random.Real8,10338.99160737,Good,2025-07-01 10:23:00.713000+00:00
Random.UInt4,23770.0,Good,2025-07-01 10:23:00.713000+00:00
Random.UInt8,20041.0,Good,2025-07-01 10:23:00.713000+00:00
test,None,Error,None
Command exceeded interval by 1344ms

Desktop (please complete the following information):

OS: Windows 10

Version: 22H2

OPC Server: Matrikon OPC Simulation Server

Python Version: 3.11 (used for OpenOpcService.exe compilation)

Environment Variables:
env.ps1

OPC_CLASS="Graybox.OPC.DAWrapper"
OPC_CLIENT="OpenOPC"
OPC_GATE_HOST="192.168.1.41"
OPC_GATE_PORT="7766"
OPC_HOST="localhost"
OPC_MODE="dcom"
OPC_SERVER="Matrikon.OPC.Simulation.1"

UPDATE:
For got more info from running command in windows you can use below function to simulate watch behavior in windows.
Add this code into your powershell $PROFILE by below command:

notepad $PROFILE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions