plc4x: [Bug]: plc4j-driver-opcua seems to leak memory

What happened?

The OPC-UA driver seem to leak memory when closing a connection object. This issue sooner or later lead to application crash with OOM error. Workaround would be to reuse connection objects, but then we face the issue #1100, which I believe renders a fix for this pretty urgent.

Screenshot from 2023-09-23 14-14-10

Example code to reproduce the issue:

PlcDriverManager driverManager = new PlcDriverManager();

AtomicBoolean running = new AtomicBoolean(true);
Runtime.getRuntime().addShutdownHook(new Thread(() -> running.set(true)));

while (running.get()) {
    PlcConnection connection = driverManager.getConnection("opcua:tcp://127.0.0.1:40185/milo?discovery=false");
    try {
        Thread.sleep(100);
    } finally {
        connection.close();
    }
}

Some additional charts

Screenshot from 2023-09-23 14-23-14

Screenshot from 2023-09-23 14-08-05

Screenshot from 2023-09-23 14-10-16

Screenshot from 2023-09-23 14-10-25

Logs

logs-before-oom.txt

Heap dumps

Version

v0.10.0

Programming Languages

  • plc4j
  • plc4go
  • plc4c
  • plc4net

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • CANopen
  • DeltaV
  • DF1
  • EtherNet/IP
  • Firmata
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • S7

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 33 (26 by maintainers)

Commits related to this issue

Most upvoted comments

Hi all,

I have checked out the specific branch:

image

I have built the nifi integrations and deployed it:

image

I didn’t had any OOM problems anymore

image

(red line is time when I replaced the plc4x nar)

Thank you very much for your support, much appreciated!

@christofe-lintermans-actemium I believe that #1007 might address some of these issues as it cleans up some of driver internals which could loose consistency over last two releases (0.10-0.11) and fall behind with stability. I am awaiting for feedback on field testing with real devices which should be completed this or next week after which I would like to merge these changes to develop. Then the Apache Nifi team will be able to produce new development build which should be free of (major) memory leaks.

I would strongly assume it’s the same issue, as from my knowledge interenally all integration modules use the same components. So this issue should probably be observalble in all integration modules.