You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "Lukas Ott (Jira)" <ji...@apache.org> on 2022/11/09 10:22:00 UTC

[jira] [Commented] (PLC4X-339) modbus connection causes memory leak

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

Lukas Ott commented on PLC4X-339:
---------------------------------

This issue has been migrated to https://github.com/apache/plc4x/issues/636

> modbus connection causes memory leak
> ------------------------------------
>
>                 Key: PLC4X-339
>                 URL: https://issues.apache.org/jira/browse/PLC4X-339
>             Project: Apache PLC4X
>          Issue Type: Bug
>          Components: Driver-Modbus
>    Affects Versions: 0.9.0
>         Environment: Windows 10; jdk1.8 32bit
>            Reporter: liangjian
>            Priority: Major
>
> Note: The version is 0.9.1.
> 1. The document (here)[https://plc4x.apache.org/users/protocols/modbus.html] seems wrong. It tells me the connection string format is: "modbus-tcp:tcp://127.0.0.1:502", but my test code throws exception saying no driver until I change it to "modbus://127.0.0.1".
> 2. My test code writes (or reads) some value via modbus tcp every 1 second, using short tcp connection (open and close every time). The memory increases every second until out-of-memory. In process monitor I find the thread count increases 1 every time the connection opens, but never releases, althought I consider the `try-block` shall closes it automatically. In fact, I see it calls `connection.close` after the `try-block`.
> Test code:
> {code:java}
>         while (true) {
>             String connectionString = "modbus://127.0.0.1";
>             try (PlcConnection plcConnection = new PlcDriverManager().getConnection(connectionString)) {
>                 PlcWriteRequest.Builder builder = plcConnection.writeRequestBuilder();
>                 builder.addItem("value-1", "holding-register:1:DINT", 30000);
>                 builder.addItem("value-2", "holding-register:3:REAL", 3.14);
>                 PlcWriteRequest writeRequest = builder.build();
>                 PlcWriteResponse response = writeRequest.execute().get();
>                 
>                 for (String fieldName : response.getFieldNames()) {
>                     if(response.getResponseCode(fieldName) == PlcResponseCode.OK) {
>                         System.out.println("Value[" + fieldName + "]: updated");
>                     }
>                     // Something went wrong, to output an error message instead.
>                     else {
>                         System.out.println("Error[" + fieldName + "]: " + response.getResponseCode(fieldName).name());                     
> 					}
>                 }
>                 System.out.println("done");
>             }
>             Thread.sleep(1000);
>         }
> {code}
> It shows the connection is not cleaned properly.
> I see it's more efficient to do this using long tcp connection (reuse 1 connection or use a pool). But short tcp connection should also work.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)