You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "Andre Vocat (Jira)" <ji...@apache.org> on 2021/05/18 06:44:00 UTC

[jira] [Commented] (PLC4X-242) nioEventLoopGroup thread leak

    [ https://issues.apache.org/jira/browse/PLC4X-242?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17346615#comment-17346615 ] 

Andre Vocat commented on PLC4X-242:
-----------------------------------

we see all so the same behaviour in 0.7.0, we are dealing actually by circumventing with following code:


EventLoop eventloop=null;
 if (((DefaultNettyPlcConnection)connection).getChannel() != null && ((DefaultNettyPlcConnection)connection).getChannel().eventLoop() != null)
 eventloop = ((DefaultNettyPlcConnection)connection).getChannel().eventLoop(); 
 
 if (this.connection != null)
 {
 this.connection.close();
 if (eventloop!= null)
 eventloop.shutdownGracefully();
 }

> nioEventLoopGroup thread leak
> -----------------------------
>
>                 Key: PLC4X-242
>                 URL: https://issues.apache.org/jira/browse/PLC4X-242
>             Project: Apache PLC4X
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 0.7.0, 0.8.0
>         Environment: Linux Raspbian Buster 10.0 / OpenJDK 13
>            Reporter: Adam Rossi
>            Priority: Critical
>
> Here is some log output from my program. You can see that the close is called on the DefaultNettyPlcConnection, but I do not see the output from the code modification that I would expect if the closeEventLoopForChannel method was being called (Either logger.info("Channel is closed, closing worker Group also") or logger.warn("Trying to remove EventLoop for Channel {} but have none stored", channel).
>  
> The nioEventLoopGroup threads continue to persist after every plcConnection. 
>  
> I hope I have built everything correctly...I checked out your branch with:
>  
> {quote}git clone --single-branch --branch bugfix/close-eventloop-after-channel [https://github.com/apache/plc4x.git]
>  {quote}And wiped out my local m2 maven repository before building the code with:
>  
> {quote}./mvnw install -DskipTests
>  {quote}I also removed references to the apache snapshot repo from my project pom and by all appearances I am using the correct 0.8.0-SNAPSHOT jars that are locally built in my local m2 repo. Here is some log info from my test:
>  
>  
> {quote}2020-08-24_10:15:43.450 DEBUG PooledPlcDriverManager - Try to borrow an object for url modbus://[192.168.0.5:503?unit-identifier=50|http://192.168.0.5:503/?unit-identifier=50]
> 2020-08-24_10:15:43.452 INFO  TcpChannelFactory - Configuring Bootstrap with Configuration{}
> 2020-08-24_10:15:43.458 DEBUG ModbusManager - Connection Metadata:
> 2020-08-24_10:15:43.459 DEBUG ModbusManager - org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection@185c140
> 2020-08-24_10:15:43.462 DEBUG Plc4xNettyWrapper - Forwarding request to plc ModbusTcpADU[transactionIdentifier=10,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=67,quantity=1]]
> 2020-08-24_10:15:43.466 DEBUG GeneratedDriverByteToMessageCodec - Sending bytes to PLC for message ModbusTcpADU[transactionIdentifier=10,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=67,quantity=1]] as data 000a00000006320300430001
> 2020-08-24_10:15:43.470 DEBUG Plc4xNettyWrapper - Forwarding request to plc ModbusTcpADU[transactionIdentifier=11,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=69,quantity=1]]
> 2020-08-24_10:15:43.471 DEBUG GeneratedDriverByteToMessageCodec - Sending bytes to PLC for message ModbusTcpADU[transactionIdentifier=11,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=69,quantity=1]] as data 000b00000006320300450001
> 2020-08-24_10:15:43.480 DEBUG Plc4xNettyWrapper - Forwarding request to plc ModbusTcpADU[transactionIdentifier=12,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=68,quantity=1]]
> 2020-08-24_10:15:43.481 DEBUG GeneratedDriverByteToMessageCodec - Sending bytes to PLC for message ModbusTcpADU[transactionIdentifier=12,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=68,quantity=1]] as data 000c00000006320300440001
> 2020-08-24_10:15:43.484 DEBUG Plc4xNettyWrapper - Forwarding request to plc ModbusTcpADU[transactionIdentifier=13,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=66,quantity=1]]
> 2020-08-24_10:15:43.485 DEBUG GeneratedDriverByteToMessageCodec - Sending bytes to PLC for message ModbusTcpADU[transactionIdentifier=13,unitIdentifier=50,pdu=ModbusPDUReadHoldingRegistersRequest[startingAddress=66,quantity=1]] as data 000d00000006320300420001
> 2020-08-24_10:15:43.489 DEBUG PooledPlcDriverManager - close called on org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection@185c140
> 2020-08-24_10:15:43.490 INFO  ReadModbusTask - Read Modbus Task Completed.
>  {quote}Some details from my code:
>  
> Getting the connection:
> {quote}PlcConnection plcConnection = pooledDriverManager.getConnection(modbusServerURI);
> if (plcConnection.isConnected()) {
>                 LOG.trace("The connection is connected");
>  } else {
>                 LOG.trace("The connection is not connected. Connecting now...");
>                 plcConnection.connect();
>  }
>  {quote}Reading the plc and closing the connection:
>  
> {quote}PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
> builder.addItem("devicename", "holding-register:1[8]");
> builder.addItem("generatorstate", "holding-register:67");
> builder.addItem("batteryvoltage", "holding-register:513[2]");
> builder.addItem("batterycurrent", "holding-register:515[2]");
> builder.addItem("pvpowerwatts", "holding-register:69[2]");
> builder.addItem("pvinputthishourkwh", "holding-register:307[2]");
> PlcReadRequest readRequest = builder.build();
> PlcReadResponse response;
>             try {
>                 response = readRequest.execute().get(5, TimeUnit.SECONDS);{quote}
> {quote}                //process response{quote}
> {quote}catch (InterruptedException | ExecutionException | TimeoutException ex) {
>                 LOG.error("Error in executing gateway read - interrupted or timed out", ex);
>             }
>         } finally {
>             plcConnection.close();
>         } catch (Exception ex) {
>             LOG.error("Error closing modbus connection", ex);
>         }
>         }{quote}
> Other details: 
> !https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif!
>  
> {quote}openjdk version: "13.0.2" 2020-01-15
> Linux Version:
> PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
> NAME="Raspbian GNU/Linux"
> VERSION="10 (buster)"{quote}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)