You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "mkribs (via GitHub)" <gi...@apache.org> on 2026/07/14 17:08:41 UTC

[I] [Bug]: S7 driver leaks Netty/protocol resources on repeated failed connect() attempts (orphaned resources, related to #2544)

mkribs opened a new issue, #2644:
URL: https://github.com/apache/plc4x/issues/2644

   ### What happened?
   
   We're running plc4j (S7 driver) inside a long-lived industrial gateway process on constrained embedded Linux hardware (512MB total RAM, JVM heap capped at `-Xmx128m`). When the remote S7 PLC becomes unreachable for an extended period (in our case ~3 hours, confirmed the PLC and network path were healthy — a purely transient outage), our application repeatedly calls `PlcDriverManager.getDefault().getConnectionManager().getConnection("s7://...")` on a backoff schedule (5-600s) to retry the connection. Each attempt times out after 5000ms without ever returning a `PlcConnection` instance to the caller.
   
   Over the ~3 hour outage (roughly 17-18 failed connect attempts), the process's resident memory (RSS) climbed from its normal baseline to ~78% of the device's total RAM, at which point the Linux kernel OOM-killer killed the JVM (confirmed via `uptime` that the device itself never rebooted — only our process died and was restarted by our process supervisor). No Java `OutOfMemoryError` was ever logged, which is consistent with the growth happening outside the JVM heap (native/off-heap), invisible to heap-based OOM detection.
   
   A thread dump taken shortly after the process restarted (before any new failures had occurred) already showed threads named `plc4x-tm-thread-*`, `plc4x-app-thread-*`, `plc4x-s7ha-thread-*`, `plc4x-evt-processor-*`, `plc4x-evt-dispatcher-*`, and `nioEventLoopGroup-*`.
   
   This looks like the "Orphaned Resources on Failed Connection" scenario discussed (but not fixed) in #2544: since `connect()` fails before ever returning a connection object, `close()` is never invoked, and whatever `EmbeddedChannel` / `HashedWheelTimer` / protocol thread pool got allocated during that attempt is never released. #2544 was closed as "not planned" after the original reporter retracted their *thread*-leak claim for the normal-disconnect path, but the *failed-connect* orphaned-resource scenario was confirmed by maintainers on that same thread and, as far as we can tell, was never itself addressed. We're filing separately since our field data (RSS growth over time + thread dump + confirmed OOM-kill) is different evidence than what was available on #2544, and might help re-evaluate whether this specific path needs a fix.
   
   **Steps to reproduce:**
   1. Configure an S7 connection (`s7://<host>:102?remote-rack=0&remote-slot=1`) to an address that is reachable at the TCP level but never completes (or is simply firewalled/unreachable so `getConnection()` always times out).
   2. Repeatedly call `getConnectionManager().getConnection(...)` on a timer (every 10-60s) for an extended period (hours), always against the same unreachable address.
   3. Monitor process RSS and `/proc/<pid>/task/*/comm` thread names over time.
   
   Happy to provide our thread-dump and RSS-over-time data if useful.
   
   ### Version
   
   0.13.1
   
   ### Programming Languages
   
   - [x] plc4j
   
   ### Protocols
   
   - [x] S7
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: S7 driver leaks Netty/protocol resources on repeated failed connect() attempts (orphaned resources, related to #2544)

Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on issue #2644:
URL: https://github.com/apache/plc4x/issues/2644#issuecomment-4972011958

   Unfortuantely this bug report is almost certainly already obsolete ... I've spent the last half year completely rewriting all PLC4J drivers and the new version will be completely Netty-free.
   
   Please give 0.14.0-SNAPSHOT a try.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: S7 driver leaks Netty/protocol resources on repeated failed connect() attempts (orphaned resources, related to #2544)

Posted by "mkribs (via GitHub)" <gi...@apache.org>.
mkribs commented on issue #2644:
URL: https://github.com/apache/plc4x/issues/2644#issuecomment-4973014997

   Thanks for the quick reply! Makes sense - confirmed on `develop`/0.14.0-SNAPSHOT that the S7/Netty stack is gone, so this specific report (Netty EventLoopGroup/thread leak) is indeed obsolete against that version.
   
   While checking `develop` I did find a smaller, unrelated fd leak in the new (Netty-free) TCP transport: `TcpTransportInstance`'s constructor doesn't close its `SocketChannel` if `bind()` or a socket-option call fails before `connect()` is reached (e.g. a pinned local port still held by a previous attempt). Filed a fix with a regression test in #2645, if you get a chance to take a look.
   
   Happy for this issue to be closed as obsolete/superseded by #2645, or however you'd like to handle it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: S7 driver leaks Netty/protocol resources on repeated failed connect() attempts (orphaned resources, related to #2544)

Posted by "sruehl (via GitHub)" <gi...@apache.org>.
sruehl closed issue #2644: [Bug]: S7 driver leaks Netty/protocol resources on repeated failed connect() attempts (orphaned resources, related to #2544)
URL: https://github.com/apache/plc4x/issues/2644


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org