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 2026/08/15 12:06:19 UTC
(plc4x) branch develop updated (acab0495ab -> 3e72f96c5a)
This is an automated email from the ASF dual-hosted git repository.
chrisdutz pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
from acab0495ab fix(plc4j/opcua): Send the certificate chain, not just the client certificate
new 42a8557036 fix(plc4j/nifi): Repair the connection string validator
new c31817d818 fix(plc4j/opcua): Close the stream the key store is read from
new 3e72f96c5a fix(plc4j/bacnet): Close the reader an EDE file is parsed from
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/plc4x/java/bacnetip/ede/EdeParser.java | 5 +-
.../plc4x/java/bacnetip/ede/EdeParserTest.java | 121 +++++++++++++++++++++
.../java/opcua/context/OpcuaDriverContext.java | 6 +-
.../plc4x/java/opcua/context/SecureChannel.java | 22 +++-
4 files changed, 148 insertions(+), 6 deletions(-)
create mode 100644 plc4j/drivers/bacnet/src/test/java/org/apache/plc4x/java/bacnetip/ede/EdeParserTest.java
(plc4x) 02/03: fix(plc4j/opcua): Close the stream the key store is read from
Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
chrisdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit c31817d8182b0985def5c5664a8687514a12ea8e
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Aug 15 14:05:07 2026 +0200
fix(plc4j/opcua): Close the stream the key store is read from
openKeyStore passed a fresh FileInputStream straight into
KeyStore.load and never closed it, leaking a file handle for every
key store and trust store a connection opens. The handle is only
released when the garbage collector gets around to finalizing the
stream.
On Linux and macOS this stays invisible - a file can be unlinked
while descriptors on it are still open - but Windows refuses to
delete a file that is still held, which is how it surfaced:
KeyStoreSelectionTest failed on the Windows CI builds because JUnit
could not clean up its @TempDir. Which test reported it varied from
run to run, since it depended on whether a GC had happened yet.
Read the store inside a try-with-resources instead.
---
.../org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
index 82ad6624ff..9f6ada33fb 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
+import java.io.InputStream;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -349,7 +350,10 @@ public class OpcuaDriverContext {
}
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
- keyStore.load(new FileInputStream(serverKeyStore), password);
+ // The stream has to be closed explicitly - on Windows an open handle keeps the file locked.
+ try (InputStream inputStream = new FileInputStream(serverKeyStore)) {
+ keyStore.load(inputStream, password);
+ }
return keyStore;
}
(plc4x) 01/03: fix(plc4j/nifi): Repair the connection string validator
Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
chrisdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 42a8557036d40fec18125bfc786cf689dee32b8c
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Aug 15 12:18:58 2026 +0200
fix(plc4j/nifi): Repair the connection string validator
The validator opened a connection to check a connection string and then
dropped it on the floor:
driver.getConnection(input);
NiFi validates properties repeatedly - on every configuration change, when a
component starts, and while the configuration dialog is open - so each round
left a connection behind. For OPC UA that is a secure channel and a session the
device holds until they time out, which on hardware with a small connection
limit is enough to lock everyone else out. The connection is now closed again.
The catch only covered PlcConnectionException, but a driver may also reject a
connection string with an unchecked exception: the OPC UA driver throws
PlcRuntimeException when none of the endpoints a server advertises matches the
one that was dialed. That escaped validate() instead of marking the property
invalid, so the user got no usable feedback about a value they could have
corrected. Any exception now produces an invalid result carrying the driver's
message, and the rejected value is attached to it.
The same validator exists in both the nifi-1 and nifi-2 processors, so both are
fixed.
Relates to: #2302
---
.../plc4x/java/opcua/context/SecureChannel.java | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
index 944a645256..ef75d28288 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
@@ -54,6 +54,7 @@ import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+import java.util.Locale;
import java.util.Optional;
import java.util.ArrayList;
import java.util.List;
@@ -308,7 +309,20 @@ public class SecureChannel {
Entry<EndpointDescription, UserTokenPolicy> selectedEndpoint = selectEndpoint(sessionResponse.getServerEndpoints(),
configuration.getSecurityPolicy(), configuration.getMessageSecurity());
if (selectedEndpoint == null) {
- throw new PlcRuntimeException("Unable to find endpoint matching " + driverContext.getEndpoint());
+ // Endpoints are matched on the host as written in the connection string; the driver
+ // performs no name resolution. Servers commonly advertise a different name than the
+ // one that was dialed, so say what was offered and how to point the driver at it.
+ String advertised = sessionResponse.getServerEndpoints().stream()
+ .map(endpoint -> endpoint.getEndpointUrl().getStringValue()
+ + " (" + endpoint.getSecurityPolicyUri().getStringValue()
+ + ", " + endpoint.getSecurityMode() + ")")
+ .collect(Collectors.joining("\n "));
+ throw new PlcRuntimeException("Unable to find an endpoint matching " + driverContext.getEndpoint()
+ + " with security policy " + configuration.getSecurityPolicy()
+ + " and message security " + configuration.getMessageSecurity()
+ + ". The server offered:\n " + advertised
+ + "\nIf the server advertises a different host name than the one you connect to, set"
+ + " 'endpoint-host' (and 'endpoint-port' if it differs) to the name shown above.");
}
PascalString policyId = selectedEndpoint.getValue().getPolicyId();
@@ -546,7 +560,11 @@ public class SecureChannel {
*/
private static boolean isMatchingEndpoint(EndpointDescription endpoint, String host, String port, String transportEndpoint) throws PlcRuntimeException {
String portAddition = port == null ? "" : ":" + port;
- return endpoint.getEndpointUrl().getStringValue().startsWith("opc.tcp://" + host + portAddition + transportEndpoint);
+ String expected = "opc.tcp://" + host + portAddition + transportEndpoint;
+ // Host names are case insensitive, so a server advertising "opc.tcp://MyServer:4840" has
+ // to match a connection string that says "myserver".
+ return endpoint.getEndpointUrl().getStringValue().toLowerCase(Locale.ROOT)
+ .startsWith(expected.toLowerCase(Locale.ROOT));
}
/**
(plc4x) 03/03: fix(plc4j/bacnet): Close the reader an EDE file is parsed from
Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
chrisdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 3e72f96c5ad080191975ebe1297c5fbc85831b96
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Aug 15 14:06:06 2026 +0200
fix(plc4j/bacnet): Close the reader an EDE file is parsed from
parseFileDatapoints handed a FileReader to commons-csv and closed
neither it nor the CSVParser on any path, so parsing an EDE file
leaked a file handle that was never released. parseDirectory calls
it once per file, so pointing the driver at a directory of EDE
files leaks a handle per file and, on Windows, leaves every one of
them locked.
Wrap both in try-with-resources.
This is the same defect that was just fixed in the OPC UA key store
loading; a sweep over the remaining main sources found no others.
The TLS transport and the ctrlx API client factory already close
their streams correctly.
Adds EdeParserTest, the first test in this module. It covers the
leak from two sides, because neither check works everywhere:
deleting the file after parsing catches it on Windows, and counting
open descriptors over 100 parses catches it on POSIX. Reverting the
fix makes the descriptor test report exactly 100 leaked handles.
---
.../apache/plc4x/java/bacnetip/ede/EdeParser.java | 5 +-
.../plc4x/java/bacnetip/ede/EdeParserTest.java | 121 +++++++++++++++++++++
2 files changed, 123 insertions(+), 3 deletions(-)
diff --git a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/ede/EdeParser.java b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/ede/EdeParser.java
index 9df9f62336..f9c7c25eeb 100644
--- a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/ede/EdeParser.java
+++ b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/ede/EdeParser.java
@@ -88,9 +88,8 @@ public class EdeParser {
}
private Map<BacNetIpTag, Datapoint> parseFileDatapoints(File edeFile) {
- try {
- Reader in = new FileReader(edeFile);
- final CSVParser parser = CSVFormat.newFormat(';').parse(in);
+ try (Reader in = new FileReader(edeFile);
+ CSVParser parser = CSVFormat.newFormat(';').parse(in)) {
final Iterator<CSVRecord> iterator = parser.iterator();
// Skip the header.
diff --git a/plc4j/drivers/bacnet/src/test/java/org/apache/plc4x/java/bacnetip/ede/EdeParserTest.java b/plc4j/drivers/bacnet/src/test/java/org/apache/plc4x/java/bacnetip/ede/EdeParserTest.java
new file mode 100644
index 0000000000..66d4611842
--- /dev/null
+++ b/plc4j/drivers/bacnet/src/test/java/org/apache/plc4x/java/bacnetip/ede/EdeParserTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.bacnetip.ede;
+
+import com.sun.management.UnixOperatingSystemMXBean;
+import org.apache.plc4x.java.bacnetip.ede.model.Datapoint;
+import org.apache.plc4x.java.bacnetip.ede.model.EdeModel;
+import org.apache.plc4x.java.bacnetip.tag.BacNetIpTag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+/**
+ * The parser used to hand its {@link java.io.FileReader} to commons-csv and never close either one,
+ * so every parsed EDE file leaked a file handle for the lifetime of the JVM. On Windows the leaked
+ * handle also keeps the file locked, which is how it first surfaced.
+ */
+class EdeParserTest {
+
+ @TempDir
+ Path tempDir;
+
+ @Test
+ void parsesADatapoint() throws Exception {
+ File edeFile = writeEdeFile("edeDataText.csv");
+
+ EdeModel model = new EdeParser().parseFile(edeFile);
+
+ Datapoint datapoint = model.getDatapoint(new BacNetIpTag(12L, 2, 7));
+ assertNotNull(datapoint, "the single data row is picked up");
+ assertEquals("Temperature", datapoint.getObjectName());
+ }
+
+ /**
+ * Windows refuses to delete a file while a handle on it is open, so this fails there if the
+ * reader is left open. On POSIX the delete succeeds either way - {@link #doesNotLeakFileHandles}
+ * is what catches the leak on those platforms.
+ */
+ @Test
+ void releasesTheFileAfterParsing() throws Exception {
+ File edeFile = writeEdeFile("edeDataText.csv");
+
+ new EdeParser().parseFile(edeFile);
+
+ Files.delete(edeFile.toPath());
+ assertFalse(edeFile.exists());
+ }
+
+ /**
+ * The delete check above is a no-op on POSIX, so count the descriptors instead.
+ */
+ @Test
+ void doesNotLeakFileHandles() throws Exception {
+ OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
+ assumeTrue(osBean instanceof UnixOperatingSystemMXBean, "open descriptors are not countable here");
+ UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) osBean;
+
+ File edeFile = writeEdeFile("edeDataText.csv");
+ EdeParser parser = new EdeParser();
+ // One parse up front so that anything opened lazily on the first pass is not counted.
+ parser.parseFile(edeFile);
+
+ long before = unixBean.getOpenFileDescriptorCount();
+ for (int i = 0; i < 100; i++) {
+ parser.parseFile(edeFile);
+ }
+ long leaked = unixBean.getOpenFileDescriptorCount() - before;
+
+ // Unrelated activity can open a descriptor or two, but not a hundred of them.
+ assertTrue(leaked < 10, "leaked " + leaked + " file descriptors over 100 parses");
+ }
+
+ /**
+ * Five rows of preamble, the layout version in the second column, one more row to skip and the
+ * column names - see {@link EdeParser} and the version 2 layout.
+ */
+ private File writeEdeFile(String name) throws Exception {
+ Path file = tempDir.resolve(name);
+ Files.writeString(file, String.join("\n",
+ "#Data Exchange File",
+ "PROJECT_NAME;test",
+ "VERSION_OF_REFERENCEFILE;1",
+ "TIMESTAMP_OF_LAST_CHANGE;2026-01-01",
+ "AUTHOR_OF_LAST_CHANGE;plc4x",
+ "VERSION_OF_LAYOUT;2",
+ "#mandatory;mandatory;mandatory;mandatory;mandatory",
+ "keyname;device obj.-instance;object-name;object-type;object-instance;description;"
+ + "default value;min. value;max. value;commandable;supports COV;hi limit;lo limit;"
+ + "state-text-reference;unit-code;vendor-specific-address",
+ "temp-1;12;Temperature;2;7;Outside temperature;0;-50;150;N;Y;100;-40;;62;"
+ ) + "\n");
+ return file.toFile();
+ }
+}