You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2023/09/29 17:16:59 UTC

[plc4x] branch develop updated: fix: Hopefully fixed the thread leakage we were seeing in several issues.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 709fa7f338 fix: Hopefully fixed the thread leakage we were seeing in several issues.
709fa7f338 is described below

commit 709fa7f338c6288ba5e87b845123bf673ab66e53
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Fri Sep 29 19:16:50 2023 +0200

    fix: Hopefully fixed the thread leakage we were seeing in several issues.
---
 .../main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java   | 9 +++++++--
 .../plc4x/java/spi/connection/DefaultNettyPlcConnection.java     | 7 -------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java
index 698da26f8e..af72f6f611 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java
@@ -21,6 +21,7 @@ package org.apache.plc4x.java.spi;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelPipeline;
+import io.netty.channel.ChannelPromise;
 import io.netty.handler.codec.MessageToMessageCodec;
 import io.vavr.control.Either;
 import java.util.concurrent.TimeoutException;
@@ -112,13 +113,11 @@ public class Plc4xNettyWrapper<T> extends MessageToMessageCodec<T, Object> {
             }
 
             @Override
-            @SuppressWarnings({"unchecked", "rawtypes"})
             public SendRequestContext<T> sendRequest(T packet) {
                 return new DefaultSendRequestContext<>(Plc4xNettyWrapper.this::registerHandler, packet, this);
             }
 
             @Override
-            @SuppressWarnings({"unchecked", "rawtypes"})
             public ExpectRequestContext<T> expectRequest(Class<T> clazz, Duration timeout) {
                 return new DefaultExpectRequestContext<>(Plc4xNettyWrapper.this::registerHandler, clazz, timeout, this);
             }
@@ -126,6 +125,12 @@ public class Plc4xNettyWrapper<T> extends MessageToMessageCodec<T, Object> {
         });
     }
 
+    @Override
+    public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
+        super.close(ctx, promise);
+        timeoutManager.stop();
+    }
+
     @Override
     protected void encode(ChannelHandlerContext channelHandlerContext, Object msg, List<Object> list) throws Exception {
 //        logger.trace("Encoding {}", plcRequestContainer);
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java
index 8731cfa8b6..9b2276a706 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java
@@ -19,8 +19,6 @@
 package org.apache.plc4x.java.spi.connection;
 
 import io.netty.channel.*;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timer;
 import org.apache.plc4x.java.api.EventPlcConnection;
 import org.apache.plc4x.java.api.authentication.PlcAuthentication;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
@@ -44,11 +42,6 @@ import java.util.stream.Stream;
 
 public class DefaultNettyPlcConnection extends AbstractPlcConnection implements ChannelExposingConnection, EventPlcConnection {
 
-    /**
-     * a {@link HashedWheelTimer} shall be only instantiated once.
-     */
-    // TODO: maybe find a way to make this configurable per jvm
-    protected final static Timer timer = new HashedWheelTimer();
     protected final static long DEFAULT_DISCONNECT_WAIT_TIME = 10000L;
     private static final Logger logger = LoggerFactory.getLogger(DefaultNettyPlcConnection.class);