This is an automated email from the ASF dual-hosted git repository.

jvanderzee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9171894683 Allow `UnixNetVConnection` to be closed anytime (#11584)
9171894683 is described below

commit 91718946839693954c75aabaa876b5e192a7102d
Author: JosiahWI <[email protected]>
AuthorDate: Fri Aug 2 15:52:15 2024 -0500

    Allow `UnixNetVConnection` to be closed anytime (#11584)
    
    A `UnixNetVConnection` only has a NetHandler when it is connected. Since it
    may be unconnected until `UnixNetVConnection::connectUp` is called, it is
    unreasonable to expect that it will always have a `NetHandler`. The unit 
test
    does fail before removing the `ink_assert`. After the patch, the unit test
    passes and valgrind does not detect any memory issues.
---
 src/iocore/net/CMakeLists.txt         | 10 ++++++++--
 src/iocore/net/UnixNetVConnection.cc  |  3 ---
 src/iocore/net/unit_tests/test_Net.cc | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/iocore/net/CMakeLists.txt b/src/iocore/net/CMakeLists.txt
index 2a11811c5e..f73e78f14a 100644
--- a/src/iocore/net/CMakeLists.txt
+++ b/src/iocore/net/CMakeLists.txt
@@ -117,8 +117,14 @@ endif()
 
 if(BUILD_TESTING)
   add_executable(
-    test_net libinknet_stub.cc NetVCTest.cc unit_tests/test_ProxyProtocol.cc 
unit_tests/test_SSLSNIConfig.cc
-             unit_tests/test_YamlSNIConfig.cc unit_tests/unit_test_main.cc
+    test_net
+    libinknet_stub.cc
+    NetVCTest.cc
+    unit_tests/test_ProxyProtocol.cc
+    unit_tests/test_SSLSNIConfig.cc
+    unit_tests/test_YamlSNIConfig.cc
+    unit_tests/unit_test_main.cc
+    unit_tests/test_Net.cc
   )
   target_link_libraries(test_net PRIVATE ts::inknet catch2::catch2)
   set(LIBINKNET_UNIT_TEST_DIR "${CMAKE_SOURCE_DIR}/src/iocore/net/unit_tests")
diff --git a/src/iocore/net/UnixNetVConnection.cc 
b/src/iocore/net/UnixNetVConnection.cc
index 31f7b52e30..c8bc8c2866 100644
--- a/src/iocore/net/UnixNetVConnection.cc
+++ b/src/iocore/net/UnixNetVConnection.cc
@@ -654,9 +654,6 @@ UnixNetVConnection::do_io_write(Continuation *c, int64_t 
nbytes, IOBufferReader
 void
 UnixNetVConnection::do_io_close(int alerrno /* = -1 */)
 {
-  // FIXME: the nh must not nullptr.
-  ink_assert(nh);
-
   // The vio continuations will be cleared in ::clear called from ::free_thread
   read.enabled    = 0;
   write.enabled   = 0;
diff --git a/src/iocore/net/unit_tests/test_Net.cc 
b/src/iocore/net/unit_tests/test_Net.cc
new file mode 100644
index 0000000000..f1a4d630b3
--- /dev/null
+++ b/src/iocore/net/unit_tests/test_Net.cc
@@ -0,0 +1,34 @@
+/** @file
+
+  Catch based unit tests for inknet
+
+  @section license License
+
+  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 "iocore/net/NetProcessor.h"
+#include "iocore/net/NetVConnection.h"
+
+#include <catch.hpp>
+
+TEST_CASE("When we allocate a VC, it should not have a server name yet.")
+{
+  NetVConnection *vc{netProcessor.allocate_vc(this_ethread())};
+  CHECK(nullptr == vc->get_server_name());
+  vc->do_io_close();
+}

Reply via email to