bakaid commented on a change in pull request #743: Minificpp 1169 - Simplify C2 
metrics collection and reporting
URL: https://github.com/apache/nifi-minifi-cpp/pull/743#discussion_r396394131
 
 

 ##########
 File path: extensions/http-curl/tests/C2JstackTest.cpp
 ##########
 @@ -16,152 +16,63 @@
  * limitations under the License.
  */
 
-#include <sys/stat.h>
 #undef NDEBUG
-#include <cassert>
-#include <utility>
-#include <chrono>
-#include <fstream>
-#include <memory>
 #include <string>
-#include <thread>
-#include <type_traits>
-#include <vector>
-#include <iostream>
-#include <sstream>
-#include "HTTPClient.h"
-#include "InvokeHTTP.h"
 #include "TestBase.h"
-#include "utils/StringUtils.h"
-#include "core/Core.h"
-#include "core/logging/Logger.h"
-#include "core/ProcessGroup.h"
-#include "core/yaml/YamlConfiguration.h"
-#include "FlowController.h"
-#include "properties/Configure.h"
-#include "unit/ProvenanceTestHelper.h"
-#include "io/StreamFactory.h"
-#include "c2/C2Agent.h"
-#include "CivetServer.h"
-#include <cstring>
-#include "protocols/RESTSender.h"
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
 
-void waitToVerifyProcessor() {
-  std::this_thread::sleep_for(std::chrono::seconds(10));
-}
-
-
-class ConfigHandler : public CivetHandler {
+class VerifyC2DescribeJstack : public VerifyC2Describe {
  public:
-  ConfigHandler() {
-    calls_ = 0;
-  }
-  bool handlePost(CivetServer *server, struct mg_connection *conn) {
-    calls_++;
-    std::string heartbeat_response = "{\"operation\" : 
\"heartbeat\",\"requested_operations\": [  {"
-          "\"operation\" : \"describe\", "
-          "\"operationid\" : \"8675309\", "
-          "\"name\": \"jstack\""
-          "}]}";
-      mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
-                "text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
-                heartbeat_response.length());
-      mg_printf(conn, "%s", heartbeat_response.c_str());
-
-
-    return true;
+  explicit VerifyC2DescribeJstack(bool isSecure)
+      : VerifyC2Describe(isSecure) {
   }
 
-  bool handleGet(CivetServer *server, struct mg_connection *conn) {
-    std::ifstream myfile(test_file_location_.c_str());
-
-    if (myfile.is_open()) {
-      std::stringstream buffer;
-      buffer << myfile.rdbuf();
-      std::string str = buffer.str();
-      myfile.close();
-      mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
-                "text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
-                str.length());
-      mg_printf(conn, "%s", str.c_str());
-    } else {
-      mg_printf(conn, "HTTP/1.1 500 Internal Server Error\r\n");
-    }
-
-    return true;
+  virtual void runAssertions() {
+    assert(LogTestController::getInstance().contains("SchedulingAgent") == 
true);
   }
-  std::string test_file_location_;
-  std::atomic<size_t> calls_;
 };
 
-int main(int argc, char **argv) {
-  mg_init_library(0);
-  LogTestController::getInstance().setInfo<minifi::FlowController>();
-  LogTestController::getInstance().setDebug<minifi::utils::HTTPClient>();
-  LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
-  LogTestController::getInstance().setTrace<minifi::c2::C2Agent>();
+class DescribeJstackHandler : public HeartbeatHandler {
+ public:
+  explicit DescribeJstackHandler(bool isSecure)
+     : HeartbeatHandler(isSecure) {
+  }
 
-  const char *options[] = { "document_root", ".", "listening_ports", "0", 0 };
-  std::vector<std::string> cpp_options;
-  for (int i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
-    cpp_options.push_back(options[i]);
+  virtual void handleHeartbeat(const rapidjson::Document& root, struct 
mg_connection * conn) {
+    sendHeartbeatResponse("DESCRIBE", "jstack", "889398", conn);
   }
 
-  CivetServer server(cpp_options);
+  virtual void handleAcknowledge(const rapidjson::Document& root) {
+    assert(root.HasMember("Flowcontroller threadpool #0") == true);
+  }
 
-  std::string port_str = std::to_string(server.getListeningPorts()[0]);
+};
 
-  ConfigHandler h_ex;
-  server.addHandler("/update", h_ex);
-  std::string key_dir, test_file_location;
+int main(int argc, char **argv) {
+  std::string key_dir, test_file_location, url;
+  url = "http://localhost:0/api/heartbeat";;
   if (argc > 1) {
-    h_ex.test_file_location_ = test_file_location = argv[1];
-    key_dir = argv[2];
+    test_file_location = argv[1];
+    if (argc > 2) {
+      url = "https://localhost:0/api/heartbeat";;
+      key_dir = argv[2];
+    }
   }
 
+  bool isSecure = false;
+  if (url.find("https") != std::string::npos) {
+    isSecure = true;
+  }
 
-  std::shared_ptr<minifi::Configure> configuration = 
std::make_shared<minifi::Configure>();
-
-  std::string c2_rest_url = "http://localhost:"; + port_str + "/update";
-
-  configuration->set("c2.rest.url", c2_rest_url);
-  configuration->set("c2.agent.heartbeat.period", "1000");
-
-  std::shared_ptr<core::Repository> test_repo = 
std::make_shared<TestRepository>();
-  std::shared_ptr<core::Repository> test_flow_repo = 
std::make_shared<TestFlowRepository>();
-
-  configuration->set(minifi::Configure::nifi_flow_configuration_file, 
test_file_location);
-
-  std::shared_ptr<minifi::io::StreamFactory> stream_factory = 
minifi::io::StreamFactory::getInstance(configuration);
-  std::shared_ptr<core::ContentRepository> content_repo = 
std::make_shared<core::repository::VolatileContentRepository>();
-  std::unique_ptr<core::FlowConfiguration> yaml_ptr = 
std::unique_ptr<core::YamlConfiguration>(
-      new core::YamlConfiguration(test_repo, test_repo, content_repo, 
stream_factory, configuration, test_file_location));
-  std::shared_ptr<TestRepository> repo = 
std::static_pointer_cast<TestRepository>(test_repo);
-
-  std::shared_ptr<minifi::FlowController> controller = 
std::make_shared<minifi::FlowController>(test_repo, test_flow_repo, 
configuration, std::move(yaml_ptr), content_repo, DEFAULT_ROOT_GROUP_NAME,
-  true);
-
-  core::YamlConfiguration yaml_config(test_repo, test_repo, content_repo, 
stream_factory, configuration, test_file_location);
+  VerifyC2DescribeJstack harness(isSecure);
 
-  std::unique_ptr<core::ProcessGroup> ptr = 
yaml_config.getRoot(test_file_location);
-  std::shared_ptr<core::ProcessGroup> pg = 
std::shared_ptr<core::ProcessGroup>(ptr.get());
-  ptr.release();
-  auto start = std::chrono::system_clock::now();
+  harness.setKeyDir(key_dir);
 
-  controller->load();
-  controller->start();
-  waitToVerifyProcessor();
+  DescribeJstackHandler responder(isSecure);
 
-  controller->waitUnload(60000);
-  auto then = std::chrono::system_clock::now();
+  harness.setUrl(url, &responder);
 
-  auto milliseconds = 
std::chrono::duration_cast<std::chrono::milliseconds>(then - start).count();
-  std::string logs = LogTestController::getInstance().log_output.str();
-  #ifndef WIN32
-  assert(logs.find("SchedulingAgent") != std::string::npos);
-  #endif
-  LogTestController::getInstance().reset();
-  assert(h_ex.calls_ <= (milliseconds / 1000) + 1);
+  harness.run(test_file_location);
 
-  return 0;
 }
 
 Review comment:
   @msharee9 @szaszm I hacked together an ASAN build with clang-10 and it 
identified the issue most likely causing this:
   ```
   =================================================================
   ==58018==ERROR: AddressSanitizer: heap-use-after-free on address 
0x603000000558 at pc 0x0000006a08df bp 0x7ffff1ddedf0 sp 0x7ffff1ddede8
   WRITE of size 4 at 0x603000000558 thread T54
       #0 0x6a08de in __gnu_cxx::__atomic_add(int volatile*, int) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/atomicity.h:53:5
       #1 0x6a08de in __gnu_cxx::__atomic_add_dispatch(int*, int) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/atomicity.h:96:7
       #2 0x6a08de in 
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_copy() 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/shared_ptr_base.h:139:9
       #3 0x6a08de in 
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__shared_count<(__gnu_cxx::_Lock_policy)2>
 const&) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/shared_ptr_base.h:735:11
       #4 0x6a08de in 
std::__shared_ptr<org::apache::nifi::minifi::utils::IdGenerator, 
(__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__shared_ptr<org::apache::nifi::minifi::utils::IdGenerator,
 (__gnu_cxx::_Lock_policy)2> const&) /usr/bin/..
   
/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/shared_ptr_base.h:1165:7
       #5 0x6a08de in 
std::shared_ptr<org::apache::nifi::minifi::utils::IdGenerator>::shared_ptr(std::shared_ptr<org::apache::nifi::minifi::utils::IdGenerator>
 const&) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/sha
   red_ptr.h:129:7
       #6 0x6a08de in 
org::apache::nifi::minifi::utils::IdGenerator::getIdGenerator() 
/home/bakaid/nifi-minifi-cpp2/libminifi/include/utils/Id.h:156:12
       #7 0x69f0b6 in 
org::apache::nifi::minifi::core::CoreComponent::CoreComponent(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char> > const&) 
/home/bakaid/nifi-minifi-cpp2/libminifi/include/core/Core.h:166:5
       #8 0x8667d8 in 
org::apache::nifi::minifi::core::Connectable::Connectable(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char> > const&) 
/home/bakaid/nifi-minifi-cpp2/libminifi/src/core/Connectable.cpp:40:7
       #9 0xc6fb47 in 
org::apache::nifi::minifi::utils::HTTPClient::HTTPClient(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char> > const&, 
std::shared_ptr<org::apache::nifi::minifi::controllers::SSLContextService>
   ) 
/home/bakaid/nifi-minifi-cpp2/extensions/http-curl/client/HTTPClient.cpp:36:7
       #10 0xc6758a in 
org::apache::nifi::minifi::c2::RESTSender::sendPayload(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char> >, 
org::apache::nifi::minifi::c2::Direction, 
org::apache::nifi::minifi::c2::C2Payload
    const&, std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >) 
/home/bakaid/nifi-minifi-cpp2/extensions/http-curl/protocols/RESTSender.cpp:106:21
       #11 0xc65637 in 
org::apache::nifi::minifi::c2::RESTSender::consumePayload(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char> > const&, 
org::apache::nifi::minifi::c2::C2Payload const&, org::apache::nifi::mini
   fi::c2::Direction, bool) 
/home/bakaid/nifi-minifi-cpp2/extensions/http-curl/protocols/RESTSender.cpp:69:10
       #12 0xc65c00 in 
org::apache::nifi::minifi::c2::RESTSender::consumePayload(org::apache::nifi::minifi::c2::C2Payload
 const&, org::apache::nifi::minifi::c2::Direction, bool) 
/home/bakaid/nifi-minifi-cpp2/extensions/http-curl/protocols/RE
   STSender.cpp
       #13 0xc65c00 in non-virtual thunk to 
org::apache::nifi::minifi::c2::RESTSender::consumePayload(org::apache::nifi::minifi::c2::C2Payload
 const&, org::apache::nifi::minifi::c2::Direction, bool) 
/home/bakaid/nifi-minifi-cpp2/extensions/h
   ttp-curl/protocols/RESTSender.cpp
       #14 0x7bb07d in 
org::apache::nifi::minifi::c2::C2Agent::performHeartBeat() 
/home/bakaid/nifi-minifi-cpp2/libminifi/src/c2/C2Agent.cpp:318:45
       #15 0x7d172a in 
org::apache::nifi::minifi::c2::C2Agent::C2Agent(std::shared_ptr<org::apache::nifi::minifi::core::controller::ControllerServiceProvider>
 const&, std::shared_ptr<org::apache::nifi::minifi::state::StateMonitor> 
const&, st
   d::shared_ptr<org::apache::nifi::minifi::Configure> const&, 
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>&)::$_0::operator()()
 const /home/bakaid/nifi-minifi-cpp2/libminifi/src/c2/C2Age
   nt.cpp:100:9
       #16 0x7d172a in 
std::_Function_handler<org::apache::nifi::minifi::utils::TaskRescheduleInfo (), 
org::apache::nifi::minifi::c2::C2Agent::C2Agent(std::shared_ptr<org::apache::nifi::minifi::core::controller::ControllerServiceProvider>
 co
   nst&, std::shared_ptr<org::apache::nifi::minifi::state::StateMonitor> 
const&, std::shared_ptr<org::apache::nifi::minifi::Configure> const&, 
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>
   &)::$_0>::_M_invoke(std::_Any_data const&) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:282:9
       #17 0xa3652b in 
std::function<org::apache::nifi::minifi::utils::TaskRescheduleInfo 
()>::operator()() const 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:687:14
       #18 0xa3652b in 
org::apache::nifi::minifi::utils::Worker<org::apache::nifi::minifi::utils::TaskRescheduleInfo>::run()
 /home/bakaid/nifi-minifi-cpp2/libminifi/include/utils/ThreadPool.h:97:16
       #19 0xa3652b in 
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>::run_tasks(std::shared_ptr<org::apache::nifi::minifi::utils::WorkerThread>)
 /home/bakaid/nifi-minifi-cpp2/libminifi/src
   /utils/ThreadPool.cpp:49:16
       #20 0xa64bfb in void std::__invoke_impl<void, void 
(org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>::*&)(std::shared_ptr<org::apache::nifi::minifi::utils::WorkerThread>),
 org::apache:
   
:nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>*&,
 
std::shared_ptr<org::apache::nifi::minifi::utils::WorkerThread>&>(std::__invoke_memfun_deref,
 void (org::apache::nifi::minifi::utils::ThreadPool<org
   
::apache::nifi::minifi::utils::TaskRescheduleInfo>::*&)(std::shared_ptr<org::apache::nifi::minifi::utils::WorkerThread>),
 
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>*&,
 std::shared_pt
   r<org::apache::nifi::minifi::utils::WorkerThread>&) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/invoke.h:73:14
       #21 0x7ffff76e86ee in execute_native_thread_routine 
/build/gcc-8-uSa_z7/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/src/c++11/../../../../../src/libstdc++-v3/src/c++11/thread.cc:80:18
       #22 0x7ffff70756da in start_thread 
/build/glibc-OTsEL5/glibc-2.27/nptl/pthread_create.c:463
       #23 0x7ffff697e88e in clone 
/build/glibc-OTsEL5/glibc-2.27/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
   
   0x603000000558 is located 8 bytes inside of 24-byte region 
[0x603000000550,0x603000000568)
   freed by thread T0 here:
       #0 0x6861bd in operator delete(void*) 
(/home/bakaid/nifi-minifi-cpp2/build/extensions/http-curl/tests/C2JstackTest+0x6861bd)
       #1 0x7ffff68a0040 in __run_exit_handlers 
/build/glibc-OTsEL5/glibc-2.27/stdlib/exit.c:108
   
   previously allocated by thread T0 here:
       #0 0x68595d in operator new(unsigned long) 
(/home/bakaid/nifi-minifi-cpp2/build/extensions/http-curl/tests/C2JstackTest+0x68595d)
       #1 0x6a0bb4 in 
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<org::apache::nifi::minifi::utils::IdGenerator*>(org::apache::nifi::minifi::utils::IdGenerator*)
 /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/
   c++/8/bits/shared_ptr_base.h:623:16
       #2 0x6a092a in 
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<org::apache::nifi::minifi::utils::IdGenerator*>(org::apache::nifi::minifi::utils::IdGenerator*,
 std::integral_constant<bool, false>) /usr/bin/../lib/gcc/x8
   6_64-linux-gnu/8/../../../../include/c++/8/bits/shared_ptr_base.h:634:4
       #3 0x6a092a in 
std::__shared_ptr<org::apache::nifi::minifi::utils::IdGenerator, 
(__gnu_cxx::_Lock_policy)2>::__shared_ptr<org::apache::nifi::minifi::utils::IdGenerator,
 void>(org::apache::nifi::minifi::utils::IdGenerator*) /usr/bin/..
   
/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/shared_ptr_base.h:1123:17
       #4 0x6a092a in 
std::shared_ptr<org::apache::nifi::minifi::utils::IdGenerator>::shared_ptr<org::apache::nifi::minifi::utils::IdGenerator,
 void>(org::apache::nifi::minifi::utils::IdGenerator*) 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../.
   ./../../include/c++/8/bits/shared_ptr.h:139:25
       #5 0x6a092a in 
org::apache::nifi::minifi::utils::IdGenerator::getIdGenerator() 
/home/bakaid/nifi-minifi-cpp2/libminifi/include/utils/Id.h:155:53
       #6 0x552d2d in __cxx_global_var_init.10 
/home/bakaid/nifi-minifi-cpp2/libminifi/src/c2/C2Agent.cpp:44:62
       #7 0x552d2d in _GLOBAL__sub_I_C2Agent.cpp 
/home/bakaid/nifi-minifi-cpp2/libminifi/src/c2/C2Agent.cpp
       #8 0x11a636c in __libc_csu_init 
(/home/bakaid/nifi-minifi-cpp2/build/extensions/http-curl/tests/C2JstackTest+0x11a636c)
   
   Thread T54 created by T53 here:
       #0 0x640f9a in pthread_create 
(/home/bakaid/nifi-minifi-cpp2/build/extensions/http-curl/tests/C2JstackTest+0x640f9a)
       #1 0x7ffff76e89a4 in __gthread_create 
/build/gcc-8-uSa_z7/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/x86_64-linux-gnu/bits/gthr-default.h:662:35
       #2 0x7ffff76e89a4 in 
std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, 
std::default_delete<std::thread::_State> >, void (*)()) 
/build/gcc-8-uSa_z7/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/src/c++11/../../../../.
   ./src/libstdc++-v3/src/c++11/thread.cc:135:37
       #3 0xa358cc in 
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>::createThread(std::function<void
 ()>&&) 
/home/bakaid/nifi-minifi-cpp2/libminifi/include/utils/ThreadPool.h:297:12
       #4 0xa30fb4 in 
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>::manageWorkers()
 /home/bakaid/nifi-minifi-cpp2/libminifi/src/utils/ThreadPool.cpp:121:30
       #5 0x7ffff76e86ee in execute_native_thread_routine 
/build/gcc-8-uSa_z7/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/src/c++11/../../../../../src/libstdc++-v3/src/c++11/thread.cc:80:18
   
   Thread T53 created by T0 here:
       #0 0x640f9a in pthread_create 
(/home/bakaid/nifi-minifi-cpp2/build/extensions/http-curl/tests/C2JstackTest+0x640f9a)
       #1 0x7ffff76e89a4 in __gthread_create 
/build/gcc-8-uSa_z7/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/x86_64-linux-gnu/bits/gthr-default.h:662:35
       #2 0x7ffff76e89a4 in 
std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, 
std::default_delete<std::thread::_State> >, void (*)()) 
/build/gcc-8-uSa_z7/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/src/c++11/../../../../.
   ./src/libstdc++-v3/src/c++11/thread.cc:135:37
       #3 0xaa0c75 in 
org::apache::nifi::minifi::FlowController::load(std::shared_ptr<org::apache::nifi::minifi::core::ProcessGroup>
 const&, bool) 
/home/bakaid/nifi-minifi-cpp2/libminifi/src/FlowController.cpp:320:20
       #4 0x68e993 in IntegrationBase::run(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >) 
/home/bakaid/nifi-minifi-cpp2/libminifi/test/integration/IntegrationBase.h:138:20
       #5 0x6948f3 in main 
/home/bakaid/nifi-minifi-cpp2/extensions/http-curl/tests/C2JstackTest.cpp:76:11
       #6 0x7ffff687eb96 in __libc_start_main 
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
   
   SUMMARY: AddressSanitizer: heap-use-after-free 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/atomicity.h:53:5
 in __gnu_cxx::__atomic_add(int volatile*, int)
   Shadow bytes around the buggy address:
     0x0c067fff8050: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fd
     0x0c067fff8060: fa fa fd fd fd fd fa fa fd fd fd fd fa fa fd fd
     0x0c067fff8070: fd fd fa fa fd fd fd fd fa fa 00 00 00 fa fa fa
     0x0c067fff8080: fd fd fd fd fa fa fd fd fd fa fa fa fd fd fd fa
     0x0c067fff8090: fa fa fd fd fd fa fa fa fd fd fd fd fa fa fd fd
   =>0x0c067fff80a0: fd fd fa fa fd fd fd fa fa fa fd[fd]fd fa fa fa
     0x0c067fff80b0: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fd
     0x0c067fff80c0: fa fa fd fd fd fd fa fa fd fd fd fa fa fa fd fd
     0x0c067fff80d0: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa
     0x0c067fff80e0: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fa
     0x0c067fff80f0: fa fa fd fd fd fa fa fa fd fd fd fa fa fa fd fd
   Shadow byte legend (one shadow byte represents 8 application bytes):
     Addressable:           00
     Partially addressable: 01 02 03 04 05 06 07
     Heap left redzone:       fa
     Freed heap region:       fd
     Stack left redzone:      f1
     Stack mid redzone:       f2
     Stack right redzone:     f3
     Stack after return:      f5
     Stack use after scope:   f8
     Global redzone:          f9
     Global init order:       f6
     Poisoned by user:        f7
     Container overflow:      fc
     Array cookie:            ac
     Intra object redzone:    bb
     ASan internal:           fe
     Left alloca redzone:     ca
     Right alloca redzone:    cb
     Shadow gap:              cc
   ==58018==ABORTING
   [Thread 0x7fffefd6f700 (LWP 58080) exited]
   [Thread 0x7ffff059c700 (LWP 58079) exited]
   [Thread 0x7ffff0da5700 (LWP 58078) exited]
   [Thread 0x7ffff15bc700 (LWP 58077) exited]
   [Thread 0x7ffff1de1700 (LWP 58076) exited]
   [Thread 0x7ffff2e69700 (LWP 58074) exited]
   [Thread 0x7ffff7fd6fc0 (LWP 58018) exited]
   [Inferior 1 (process 58018) exited with code 01]
   ```
   
   What happens here is that the statically initialized variables get freed on 
`atexit` when the main thread stops. 
   Unfortunately, the threads executing the C2 functions seem to live longer 
than the main thread, and they try to use the IdGenerator and the Logger (both 
of which I have observed to crash), causing a use-after-free. This fits the 
symptoms perfectly, but the exact reason why the threadpool lives longer than 
the main thread has to be figured out (we have a lot of shared_ptr cycles, so 
destructors are not potentially called, we most likely have to manually ensure 
that these threads are stopped before exiting `main`).
   
   @msharee9 you will have to ensure that the C2 threads (and all threads) shut 
down before we exit main. Hopefully this is only an issue in IntegrationTests, 
but it might be an issue that is present in the real usage of the C2.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to