gustavoschewinski commented on issue #1732:
URL: https://github.com/apache/plc4x/issues/1732#issuecomment-2301338673
Hi @splatch,
Thanks a lot for your help—I really appreciate it.
I suspected the issue might be the same, so I'm using the 0.13-SNAPSHOT
version for everything, but still didn't make any difference.
```xml
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-api</artifactId>
<version>0.13.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-driver-opcua</artifactId>
<version>0.13.0-SNAPSHOT</version>
</dependency>
```
I have a few other ideas that might be causing the problem, so I’ll share
all the information I’ve gathered:
1. The issue always occurs when the channel lifetime is about to expire, and
the secure channel should be renewed. For example, when I set the channel
lifetime to 1 minute, the problem occurs within that 1-minute period. This is
one reason I believe it’s not related to resource leaks, as mentioned in [this
issue](https://github.com/apache/plc4x/issues/1364).
As mentioned earlier, I tried adding `tcp.keep-alive` in hopes of
facilitating the reconnection, but it’s still not working. Unfortunately, I’m
still unable to pinpoint where the error is coming from.
3. When I check the Prosys OPCUA simulator logs, I can see that it doesn’t
attempt to renew the connection; instead, it just closes the channel. Do I need
to enable something in the simulator? I’m attaching the logs for your reference.
```
08/21/2024 09:27:55.596 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-2]
com.prosysopc.ua.stack.transport.tcp.nio.f [] -
OpcTcpServer(opc.tcp(/[0:0:0:0:0:0:0:0]:53530,
(opc.tcp://Yoshi.lab.mtu-digilab.io:53530
[[http://opcfoundation.org/UA/SecurityPolicy#None,None]])(opc.tcp://Yoshi.lab.mtu-digilab.io:53530/OPCUA/SimulationServer
[[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,SignAndEncrypt]]))):
/10.1.10.92:47938 connected
08/21/2024 09:27:56.502 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-4]
com.prosysopc.ua.stack.transport.tcp.nio.f [] -
OpcTcpServer(opc.tcp(/[0:0:0:0:0:0:0:0]:53530,
(opc.tcp://Yoshi.lab.mtu-digilab.io:53530
[[http://opcfoundation.org/UA/SecurityPolicy#None,None]])(opc.tcp://Yoshi.lab.mtu-digilab.io:53530/OPCUA/SimulationServer
[[http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256,SignAndEncrypt]]))):
/10.1.10.92:47950 connected
08/21/2024 09:27:57.376 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.432 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.444 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.451 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.460 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - Certificate
'332E73BEB6F91AD8A6779EDB866FDFE332F3DE09' added to trusted certificates.
08/21/2024 09:27:57.486 INFO [OPC-UA-Stack-Blocking-Work-Executor-1]
com.prosysopc.ua.stack.transport.tcp.nio.h [] - SecureChannel opened;
SecurityToken(Id=1, secureChannelId=1, creationTime=21.08.2024, 09:27:57,
lifetime=50000)
08/21/2024 09:27:57.759 INFO [OPC-UA-Stack-Blocking-Work-Executor-2]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.765 INFO [OPC-UA-Stack-Blocking-Work-Executor-2]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.769 INFO [OPC-UA-Stack-Blocking-Work-Executor-2]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.775 INFO [OPC-UA-Stack-Blocking-Work-Executor-2]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:27:57.777 INFO [OPC-UA-Stack-Blocking-Work-Executor-2]
com.prosysopc.ua.stack.cert.d [] - Certificate
'332E73BEB6F91AD8A6779EDB866FDFE332F3DE09' added to trusted certificates.
08/21/2024 09:27:57.800 INFO [OPC-UA-Stack-Blocking-Work-Executor-2]
com.prosysopc.ua.server.ab [] - Session created: UaSession:OPCUA
client for the Apache PLC4X:PLC4J project:dzQ381Tfp8FvZtKLUZ11
(ID=ns=1;g=e6b02fa6-6e6a-4aa6-b3e8-4e986030ae9e
Token=b=F/3BaxFLVRA/5jaBUaZB+7ooRmFWFn3BOACcoOJVC4Q= Channel=(SecureChannelId=1
State=Open URL=opc.tcp://Yoshi.lab.mtu-digilab.io:53530/OPCUA/SimulationServer
SecurityPolicy=http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256
RemoteAddress=/10.1.10.92:47950))
08/21/2024 09:27:58.107 INFO [OPC-UA-Stack-Blocking-Work-Executor-4]
com.prosysopc.ua.server.ab [] - Session activated:
UaSession:OPCUA client for the Apache PLC4X:PLC4J project:dzQ381Tfp8FvZtKLUZ11
(ID=ns=1;g=e6b02fa6-6e6a-4aa6-b3e8-4e986030ae9e
Token=b=F/3BaxFLVRA/5jaBUaZB+7ooRmFWFn3BOACcoOJVC4Q= Channel=(SecureChannelId=1
State=Open URL=opc.tcp://Yoshi.lab.mtu-digilab.io:53530/OPCUA/SimulationServer
SecurityPolicy=http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256
RemoteAddress=/10.1.10.92:47950))
08/21/2024 09:28:35.814 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:28:35.820 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:28:35.826 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:28:35.831 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - CRL initialized from
C:\Users\gustavo.schewinski\.prosysopc\prosys-opc-ua-simulation-server\PKI\CA\issuers\crl\ca.crl:
no revoked certificates
08/21/2024 09:28:35.832 INFO [OPC-UA-Stack-Non-Blocking-Work-Executor-8]
com.prosysopc.ua.stack.cert.d [] - Certificate
'332E73BEB6F91AD8A6779EDB866FDFE332F3DE09' added to trusted certificates.
08/21/2024 09:28:35.837 INFO [OPC-UA-Stack-Blocking-Work-Executor-14]
com.prosysopc.ua.stack.transport.tcp.nio.h [] - Secure Channel closed,
token=SecurityToken(Id=1, secureChannelId=1, creationTime=21.08.2024, 09:27:57,
lifetime=50000)
08/21/2024 09:28:35.838 INFO [OPC-UA-Stack-Blocking-Work-Executor-14]
com.prosysopc.ua.stack.transport.a.a [] - Channel closed: Id=1
```
4. Below is the full code I’m using to establish the connection and retrieve
data. Perhaps I’m missing some important configuration:
```java
import org.apache.plc4x.java.DefaultPlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;
import java.util.concurrent.TimeUnit;
public class App {
public static void main(String[] args) {
DefaultPlcDriverManager driverManager = new
DefaultPlcDriverManager();
String username = "admin";
String password = "admin";
String securityPolicy = "Basic256Sha256";
String keyStoreFile =
"/home/digilab/help/test2/demo_2/test/client/client_cert.p12";
String serverCertificate =
"/home/digilab/help/test2/demo_2/test/SimulationServer@Yoshi_2048.der";
String keyStorePassword = "gustavo";
String messageSecurity = "SIGN_ENCRYPT";
String connectionString = String.format(
"opcua:tcp://Yoshi.lab.mtu-digilab.io:53530/OPCUA/SimulationServer?discovery=false"
);
connectionString += !username.isBlank() ?
String.format("&username=%s", username) : "";
connectionString += !password.isBlank() ?
String.format("&password=%s", password) : "";
connectionString += !securityPolicy.isBlank() ?
String.format("&security-policy=%s", securityPolicy) : "";
connectionString += !messageSecurity.isBlank() ?
String.format("&message-security=%s", messageSecurity) : "";
connectionString += !serverCertificate.isBlank() ?
String.format("&server-certificate-file=%s", serverCertificate) : "";
connectionString += !keyStoreFile.isBlank() ?
String.format("&key-store-file=%s", keyStoreFile) : "";
connectionString += !keyStorePassword.isBlank() ?
String.format("&key-store-password=%s", keyStorePassword) : "";
connectionString += String.format("&tcp.keep-alive=%b", true);
connectionString += String.format("&channel-lifetime=%d", 50000);
System.out.println("Connection String: " + connectionString);
try (PlcConnection plcConnection =
driverManager.getConnection(connectionString)) {
System.out.println("Connected to the server");
System.out.println("Connection metadata: " +
plcConnection.getMetadata());
while (true) {
PlcReadRequest.Builder builder =
plcConnection.readRequestBuilder();
System.out.println("Builder: " + builder);
System.out.println("Builder: " + builder.getClass());
System.out.println("Builder: " + plcConnection);
builder.addTagAddress("constant", "ns=3;i=1002");
PlcReadRequest readRequest = builder.build();
PlcReadResponse response = readRequest.execute().get(5000,
TimeUnit.MILLISECONDS);
for (String tagName : response.getTagNames()) {
System.out.println("Value[" + tagName + "]: " +
response.getObject(tagName));
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.println("" + e);
}
}
}
```
5. The PLC4x Java logs don’t indicate any issues. Since the logs are quite
extensive, I’m attaching them in case you might know where to look.
[java_log.txt](https://github.com/user-attachments/files/16687636/java_log.txt)
That's all. Thank again for your support! I hope we can find a solution
together
Best,
Gustavo.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]