You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "michele-tramonti (via GitHub)" <gi...@apache.org> on 2025/09/06 12:34:47 UTC

[I] [Bug]: S7 protocol leaks memory

michele-tramonti opened a new issue, #2248:
URL: https://github.com/apache/plc4x/issues/2248

   ### What happened?
   
   i'm using plc4j version 0.13.0, connecting to S7_400.
   sometimes (I'm not able to identify the specific reason or pattern) i see this error in log:
   `[2025-09-04 15:51:56] [info] 2025-09-04 15:51:56.923 ERROR 1894504 --- [tLoopGroup-24-1] io.netty.util.ResourceLeakDetector       : LEAK: ByteBuf.release() was not called before it's garbage-collected. See https://netty.io/wiki/reference-counted-objects.html for more information.
   [2025-09-04 15:51:56] [info] Recent access records:
   [2025-09-04 15:51:56] [info] Created at:
   [2025-09-04 15:51:56] [info] #011io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:410)
   [2025-09-04 15:51:56] [info] #011io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188)
   [2025-09-04 15:51:56] [info] #011io.netty.buffer.UnsafeByteBufUtil.copy(UnsafeByteBufUtil.java:454)
   [2025-09-04 15:51:56] [info] #011io.netty.buffer.PooledUnsafeDirectByteBuf.copy(PooledUnsafeDirectByteBuf.java:216)
   [2025-09-04 15:51:56] [info] #011io.netty.buffer.AbstractByteBuf.copy(AbstractByteBuf.java:1194)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.s7.readwrite.protocol.S7HMuxImpl.encode(S7HMuxImpl.java:136)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.s7.readwrite.protocol.S7HMuxImpl.encode(S7HMuxImpl.java:1)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageCodec$2.encode(MessageToMessageCodec.java:85)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:90)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:130)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:891)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:113)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.ByteToMessageCodec.write(ByteToMessageCodec.java:108)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:891)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:130)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:891)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113)
   [2025-09-04 15:51:56] [info] #011io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:130)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:891)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:956)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:982)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:950)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:1000)
   [2025-09-04 15:51:56] [info] #011io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:974)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.spi.Plc4xNettyWrapper$1.sendToWire(Plc4xNettyWrapper.java:100)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.spi.internal.DefaultSendRequestContext.handle(DefaultSendRequestContext.java:108)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.spi.internal.DefaultSendRequestContext.handle(DefaultSendRequestContext.java:1)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.s7.readwrite.protocol.S7ProtocolLogic.lambda$42(S7ProtocolLogic.java:1535)
   [2025-09-04 15:51:56] [info] #011org.apache.plc4x.java.spi.transaction.RequestTransactionManager$TransactionOperation.run(RequestTransactionManager.java:225)
   [2025-09-04 15:51:56] [info] #011java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
   [2025-09-04 15:51:56] [info] #011java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
   [2025-09-04 15:51:56] [info] #011java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
   [2025-09-04 15:51:56] [info] #011java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
   [2025-09-04 15:51:56] [info] #011java.base/java.lang.Thread.run(Thread.java:829)`
   
   ### Version
   
   v0.13.0
   
   ### Programming Languages
   
   - [ ] plc4c
   - [ ] plc4go
   - [x] plc4j
   - [ ] plc4net
   - [ ] plc4py
   
   ### Protocols
   
   - [ ] AB-Ethernet
   - [ ] ADS /AMS
   - [ ] BACnet/IP
   - [ ] C-Bus
   - [ ] CANopen
   - [ ] EtherNet/IP
   - [ ] Firmata
   - [ ] IEC-69870
   - [ ] KNXnet/IP
   - [ ] Modbus
   - [ ] OPC-UA
   - [ ] Profinet
   - [x] S7
   - [ ] S7-light


-- 
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 protocol leaks memory

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

   here is a heap dump from last week when the issue occured:
   
   [heapdump-1757318542419.zip](https://github.com/user-attachments/files/22335992/heapdump-1757318542419.zip)


-- 
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 protocol leaks memory

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

   And if you're not relying on the subscription support, you can try the s7-light driver. 


-- 
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 protocol leaks memory

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

   make sure to use `-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/somedir"` to capture more details on what the offenders are


-- 
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 protocol leaks memory

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

   The S7 driver was completely rewritten ... Claude marked this issue as obsolete. Closing it for that ... if you still happen to run into this, please feel free to open a new issue after testing with the 1.0.0 version (-SNAPSHOT or the full version after it's released)


-- 
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 protocol leaks memory

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

   Hello,
   we have the same issue.
   plc4j version 0.12.0 connected to a S7_300.
   The application runs 24/7.
   It reads every second from the PLC and writes event based every few seconds.
   Sometimes it takes 1-2 weeks until an OutOfMemmoryError, sometimes it's over one month.
   Seems like it directly allocates memory and never releases it.
   
   
   2025-07-21 08:49:33,460  INFO | plc4x-tm-thread-2    | o.a.p.java.spi.transaction.RequestTransactionManager    | java.lang.OutOfMemoryError: Cannot reserve 4194304 bytes of direct buffer memory (allocated: 2118267416, limit: 2122317824)
   2025-07-21 08:49:42,987  WARN | scheduling-1         | de.myApp.plcbridge.s7.S7Reader                | Could not execute read request!
   java.util.concurrent.ExecutionException: org.apache.plc4x.java.api.exceptions.PlcProtocolException: Error reading
   	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
   	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
   	at de.myApp.plcbridge.s7.S7Reader.readFromPlc(S7Reader.java:66)
   	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
   	at org.springframework.scheduling.support.ScheduledMethodRunnable.runInternal(ScheduledMethodRunnable.java:130)
   	at org.springframework.scheduling.support.ScheduledMethodRunnable.lambda$run$2(ScheduledMethodRunnable.java:124)
   	at io.micrometer.observation.Observation.observe(Observation.java:498)
   	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:124)
   	at org.springframework.scheduling.config.Task$OutcomeTrackingRunnable.run(Task.java:85)
   	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
   	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
   	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
   	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
   	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
   	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
   	at java.base/java.lang.Thread.run(Thread.java:1583)
   Caused by: org.apache.plc4x.java.api.exceptions.PlcProtocolException: Error reading
   	at org.apache.plc4x.java.s7.readwrite.protocol.S7ProtocolLogic.lambda$18(S7ProtocolLogic.java:314)
   	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863)
   	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841)
   	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
   	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2194)
   	at org.apache.plc4x.java.s7.readwrite.protocol.S7ProtocolLogic$TransactionErrorCallback.accept(S7ProtocolLogic.java:2202)
   	at org.apache.plc4x.java.s7.readwrite.protocol.S7ProtocolLogic$TransactionErrorCallback.accept(S7ProtocolLogic.java:1)
   	at org.apache.plc4x.java.spi.Plc4xNettyWrapper.lambda$8(Plc4xNettyWrapper.java:253)
   	at org.apache.plc4x.java.spi.netty.NettyHashTimerTimeoutManager.lambda$0(NettyHashTimerTimeoutManager.java:55)
   	at io.netty.util.HashedWheelTimer$HashedWheelTimeout.run(HashedWheelTimer.java:713)
   	at io.netty.util.concurrent.ImmediateExecutor.execute(ImmediateExecutor.java:34)
   	at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:701)
   	at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:787)
   	at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:501)
   	... 1 common frames omitted
   Caused by: java.util.concurrent.TimeoutException: null
   	at org.apache.plc4x.java.spi.netty.NettyHashTimerTimeoutManager.lambda$0(NettyHashTimerTimeoutManager.java:54)
   	... 6 common frames omitted`
   


-- 
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 protocol leaks memory

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

   Hello,
   I have 0.13.0-SNAPSHOT running 24/7, with some sporadic disconnection, but never a memory consumption error.
   Can you tell me your use case so I can replicate the problem? Next week I'll have access to an S7-400 (417) in the office.
   I usually use the profiler to detect a memory leak; if you can use the "jconsole" and take a screenshot, that might help.
   Best regards,


-- 
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 protocol leaks memory

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

   Thanks glcj for your reply. My use case is as follows: I have a Spring Boot application running on a Tomcat server, with a service method called every 10 seconds that reads some values ​​from the S7 PLC, saving them to the database, and sends other values ​​to the PLC by reading them from the database. The peculiarity of this method is that it is internally separated into three sequential parts, each of which opens and closes (with a Java try-with) the connection to the PLC.
   
   thank you chrisdutz for your reply, I hadn't thought about it: maybe I can 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 protocol leaks memory

Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz closed issue #2248: [Bug]: S7 protocol leaks memory
URL: https://github.com/apache/plc4x/issues/2248


-- 
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