HTHou commented on code in PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#discussion_r3963937521


##########
iotdb-client/client-cpp/src/session/Session.cpp:
##########
@@ -1188,9 +1190,11 @@ void Session::close() {
       impl_->defaultSessionConnection_.reset();
     }
   } catch (...) {
+    impl_->nodesSupplier_.reset();
     impl_->isClosed_ = true;
     throw;
   }
+  impl_->nodesSupplier_.reset();

Review Comment:
   [P2] Check the Session state before dereferencing nodesSupplier_ in the 
query path. With lazy initialization in open() and this reset in close(), 
nodesSupplier_ can now be null. However, Impl::getQuerySessionConnection() 
still calls nodesSupplier_->getQueryEndPoint() before reaching 
getDefaultSessionConnection(), which performs the closed-session check. 
Consequently, executeQueryStatement() before open(), after close(), or after a 
failed open() dereferences a null pointer instead of throwing the existing 
connection exception. The C API's exception handler cannot catch this crash 
either. Please check the Session state before accessing the supplier and add 
regression coverage for these three cases. The same issue is reproducible from 
the call sequence Session session("127.0.0.1", 6667); 
session.executeQueryStatement("SHOW VERSION"); without needing a running server.



##########
.github/workflows/multi-language-client.yml:
##########
@@ -198,9 +198,15 @@ jobs:
         # (was causing problems on windows, but could cause problem on linux, 
when updating the thrift module)
         run: |
           if [[ "${{ matrix.os }}" == "windows-2025-vs2026" ]]; then
-            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am 
-Dcmake.generator="Visual Studio 18 2026"
+            # The Windows standalone server scripts do not terminate reliably 
on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS 
server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am 
-DskipTests -Diotdb.openssl.from.source=OFF -Dcmake.generator="Visual Studio 18 
2026"
+          elif [[ "${{ runner.os }}" == "Windows" ]]; then
+            # The Windows standalone server scripts do not terminate reliably 
on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS 
server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am 
-DskipTests -Diotdb.openssl.from.source=OFF

Review Comment:
   Adding -DskipTests to both Windows jobs removes all existing C++ test 
coverage, including the server-independent sessionUtilsTest, rather than just 
the TLS/mTLS phases affected by standalone-server shutdown. Also, every 
platform now passes -Diotdb.openssl.from.source=OFF, so a green PR check no 
longer exercises the default source-build path or the new macOS relocation 
logic; client-cpp-package.yml does not run on pull_request. Could we retain the 
independent Windows tests, restore server tests once shutdown is fixed, and 
include at least one default-provider build/relocation check before merge?



##########
iotdb-client/client-cpp/test/cpp/RpcSslIotdbE2eTest.cpp:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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
+ *
+ *     http://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.
+ */
+
+#include <catch.hpp>
+
+#include <cstdlib>
+#include <memory>
+#include <string>
+
+#include "Session.h"
+#include "SessionBuilder.h"
+#include "SessionC.h"
+#include "SessionDataSet.h"
+#include "SessionPool.h"
+#include "TableSessionBuilder.h"
+
+namespace {
+
+std::string fixture(const std::string& name) {
+  return std::string(IOTDB_TEST_FIXTURES_DIR) + "/tls/" + name;
+}
+
+bool mutualTlsEnabled() {
+  const char* value = std::getenv("IOTDB_CPP_SSL_MUTUAL_AUTH");
+  return value != nullptr && std::string(value) == "1";
+}
+
+template <typename Builder> void configureTls(Builder& builder) {
+  builder.useSSL(true)->trustCertFilePath(fixture("ca.crt"));
+  if (mutualTlsEnabled()) {
+    builder.clientCertificateFilePath(fixture("client.crt"))
+        ->clientPrivateKeyFilePath(fixture("client.key"));
+  }
+}
+
+SslConfig sslConfig() {
+  SslConfig config;
+  config.useSsl = true;
+  config.trustCertFilePath = fixture("ca.crt");
+  if (mutualTlsEnabled()) {
+    config.clientCertificateFilePath = fixture("client.crt");
+    config.clientPrivateKeyFilePath = fixture("client.key");
+  }
+  return config;
+}
+
+void requireDataSet(std::unique_ptr<SessionDataSet> dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(dataSet->hasNext());
+  REQUIRE(dataSet->next() != nullptr);
+  dataSet->closeOperationHandle();
+}
+
+void requireCDataSet(CSessionDataSet* dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(ts_dataset_has_next(dataSet));
+  CRowRecord* row = ts_dataset_next(dataSet);
+  REQUIRE(row != nullptr);
+  ts_row_record_destroy(row);
+  ts_dataset_destroy(dataSet);
+}
+
+} // namespace
+
+TEST_CASE("C++ APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  SessionBuilder treeBuilder;
+  
treeBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(treeBuilder);
+  auto treeSession = treeBuilder.build();
+  requireDataSet(treeSession->executeQueryStatement("SHOW VERSION"));
+  treeSession->close();
+
+  TableSessionBuilder tableBuilder;
+  
tableBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(tableBuilder);
+  auto tableSession = tableBuilder.build();
+  requireDataSet(tableSession->executeQueryStatement("SHOW VERSION"));
+  tableSession->close();
+
+  SessionPoolBuilder poolBuilder;
+  
poolBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(poolBuilder);
+  auto pool = poolBuilder.build();
+  auto pooledDataSet = pool->executeQueryStatement("SHOW VERSION");
+  REQUIRE(pooledDataSet->hasNext());
+  REQUIRE(pooledDataSet->next() != nullptr);
+  pool->close();
+}
+
+TEST_CASE("C APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  const std::string certificatePath = fixture("client.crt");
+  const std::string privateKeyPath = fixture("client.key");
+  const char* cert = mutualTlsEnabled() ? certificatePath.c_str() : nullptr;
+  const char* key = mutualTlsEnabled() ? privateKeyPath.c_str() : nullptr;
+
+  CSession* treeSession = ts_session_new("127.0.0.1", 6667, "root", "root");
+  REQUIRE(treeSession != nullptr);
+  REQUIRE(ts_session_set_ssl_config(treeSession, fixture("ca.crt").c_str(), 
cert, key) == TS_OK);
+  REQUIRE(ts_session_open(treeSession) == TS_OK);
+  CSessionDataSet* treeDataSet = nullptr;
+  REQUIRE(ts_session_execute_query(treeSession, "SHOW VERSION", &treeDataSet) 
== TS_OK);
+  requireCDataSet(treeDataSet);
+  REQUIRE(ts_session_close(treeSession) == TS_OK);
+  ts_session_destroy(treeSession);
+
+  CTableSession* tableSession = ts_table_session_new_with_ssl(
+      "127.0.0.1", 6667, "root", "root", "", fixture("ca.crt").c_str(), cert, 
key);
+  REQUIRE(tableSession != nullptr);
+  CSessionDataSet* tableDataSet = nullptr;
+  REQUIRE(ts_table_session_execute_query(tableSession, "SHOW VERSION", 
&tableDataSet) == TS_OK);
+  requireCDataSet(tableDataSet);
+  REQUIRE(ts_table_session_close(tableSession) == TS_OK);
+  ts_table_session_destroy(tableSession);
+}
+
+TEST_CASE("TLS node discovery uses the final SSL configuration and supports 
failover", "[tls]") {
+  std::vector<std::string> bootstrapNodes = {"127.0.0.1:1", "127.0.0.1:6667"};
+  Session session(bootstrapNodes, "root", "root");
+  session.setSslConfig(sslConfig());
+  session.open();
+  requireDataSet(session.executeQueryStatement("SHOW VERSION"));

Review Comment:
   This test does not establish that TLS node discovery or post-connection 
failover works: the reachable address is already in bootstrapNodes, and 
initDefaultSessionConnection() can connect to it even if every discovery 
request fails. Thus the original stale-SSL-config issue could still pass this 
test. Could we assert that discovery learns an endpoint absent from the 
bootstrap list, then make the initial endpoint unavailable and verify a query 
succeeds through the discovered endpoint? A focused test with controlled 
discovery responses would also work if a multi-node integration test is too 
costly.



-- 
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]

Reply via email to