Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YCQL] Uncaught exception when handling wrong CQL timestamp format #13064

Closed
mbautin opened this issue Jun 27, 2022 · 10 comments · Fixed by yugabyte/yugabyte-db-thirdparty#127
Closed
Assignees
Labels
area/ycql Yugabyte CQL (YCQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@mbautin
Copy link
Contributor

mbautin commented Jun 27, 2022

Jira Link: DB-2787

Description

image

ts2|pid295891|:11262 libc++abi: terminating with uncaught exception of type boost::wrapexcept<boost::gregorian::bad_month>: Month number is out of range 1..12
ts2|pid295891|:11262 *** Aborted at 1656024028 (unix time) try "date -d @1656024028" if you are using GNU date ***
ts2|pid295891|:11262 PC: @                0x0 (unknown)
ts2|pid295891|:11262 *** SIGABRT (@0x71000483d3) received by PID 295891 (TID 0x7f2b6d429700) from PID 295891; stack trace: ***
ts2|pid295891|:11262     @     0x7f2b7a0970a7 __GI_raise
ts2|pid295891|:11262     @     0x7f2b7a0984aa __GI_abort
ts2|pid295891|:11262     @          0x4233681 abort_message
ts2|pid295891|:11262     @          0x42332ea demangling_terminate_handler()
ts2|pid295891|:11262     @          0x4232e95  std::__terminate()
ts2|pid295891|:11262     @          0x4235ff1  __cxxabiv1::call_terminate()
ts2|pid295891|:11262     @          0x4235db8  __cxxabiv1::scan_eh_tab()
ts2|pid295891|:11262     @          0x4235198 __gxx_personality_v0
ts2|pid295891|:11262     @          0x2a4be33 unwind_phase2
ts2|pid295891|:11262     @          0x2a4c2f6 _Unwind_Resume
ts2|pid295891|:11262     @          0x2ced406  boost::CV::simple_exception_policy<>::on_error()
ts2|pid295891|:11262     @          0x3880b32  yb::DateTime::TimestampFromString()
ts2|pid295891|:11262     @          0x3b03b7a  yb::ql::Executor::PTConstToPB()
ts2|pid295891|:11262     @          0x3aff8d7  yb::ql::Executor::ColumnArgsToPB()
ts2|pid295891|:11262     @          0x3b1def0  yb::ql::Executor::ExecTreeNode()
ts2|pid295891|:11262     @          0x3b32b7a  yb::ql::Executor::Execute()
ts2|pid295891|:11262     @          0x3b32931  yb::ql::Executor::ExecuteAsync()
ts2|pid295891|:11262     @          0x3aec075  yb::ql::QLProcessor::ExecuteAsync()
ts2|pid295891|:11262     @          0x3aeb9f3  yb::ql::QLProcessor::RunAsync()
ts2|pid295891|:11262     @          0x3ab8985  yb::cqlserver::CQLProcessor::ProcessRequest()
ts2|pid295891|:11262     @          0x3ac2e9c  yb::cqlserver::CQLProcessor::ProcessCall()
ts2|pid295891|:11262     @          0x3ae4db6  yb::cqlserver::CQLServiceImpl::Handle()
ts2|pid295891|:11262     @          0x34c069e  yb::rpc::ServicePoolImpl::Handle()
ts2|pid295891|:11262     @          0x34120e4  yb::rpc::InboundCall::InboundCallTask::Run()
ts2|pid295891|:11262     @          0x34cf5bc  yb::rpc::(anonymous namespace)::Worker::Execute()
ts2|pid295891|:11262     @          0x3a96443  yb::Thread::SuperviseThread()
ts2|pid295891|:11262     @     0x7f2b79c4b694 start_thread
ts2|pid295891|:11262     @     0x7f2b7a14a41d __clone
@mbautin mbautin added area/docdb YugabyteDB core features status/awaiting-triage Issue awaiting triage labels Jun 27, 2022
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Jun 27, 2022
@m-iancu m-iancu assigned sureshdash2022-yb and unassigned m-iancu Jun 28, 2022
@yugabyte-ci yugabyte-ci removed the status/awaiting-triage Issue awaiting triage label Jun 28, 2022
@yugabyte-ci yugabyte-ci added area/ycql Yugabyte CQL (YCQL) and removed area/docdb YugabyteDB core features labels Jul 20, 2022
@yugabyte-ci yugabyte-ci changed the title [DocDB] Uncaught exception when handling wrong CQL timestamp format [YCQL] Uncaught exception when handling wrong CQL timestamp format Jul 20, 2022
@mbautin
Copy link
Contributor Author

mbautin commented Jul 26, 2022

This is an LTO specific issue. Also it seems to be specific to Boost exceptions. If I throw an std::exception from my test directly, it gets caught fine.

Getting this stack trace with lldb:

* thread #1, name = 'tostring-test-l', stop reason = signal SIGABRT
  * frame #0: 0x00007f2d53e380a7 libc.so.6`__GI_raise(sig=6) at raise.c:54
    frame #1: 0x00007f2d53e394aa libc.so.6`__GI_abort at abort.c:89
    frame #2: 0x00000000024aa341 tostring-test-lto`::abort_message(format=<unavailable>) at abort_message.cpp:78:5
    frame #3: 0x00000000024a9faa tostring-test-lto`demangling_terminate_handler() at cxa_default_handlers.cpp:66:21
    frame #4: 0x00000000024a9b56 tostring-test-lto`std::__terminate(func=<unavailable>)()) at cxa_handlers.cpp:59:9
    frame #5: 0x00000000024ac36d tostring-test-lto`__cxxabiv1::scan_eh_tab(results=0x00007ffe4e58ec60, actions=<unavailable>, native_exception=false, unwind_exception=<unavailable>, context=<unavailable>)::scan_results&, _Unwind_Action, bool, _Unwind_Exception*, _Unwind_Context*) at cxa_personality.cpp:0:40
    frame #6: 0x00000000024abc10 tostring-test-lto`::__gxx_personality_v0(version=<unavailable>, actions=_UA_CLEANUP_PHASE, exceptionClass=<unavailable>, unwind_exception=0x00000000053fe420, context=0x00007ffe4e58f218) at cxa_personality.cpp:947:5
    frame #7: 0x0000000002047d03 tostring-test-lto`unwind_phase2(uc=<unavailable>, cursor=0x00007ffe4e58f218, exception_object=0x00000000053fe420) at UnwindLevel1.c:197:11
    frame #8: 0x0000000002048846 tostring-test-lto`_Unwind_Resume(exception_object=0x00000000053fe420) at UnwindLevel1.c:394:5
    frame #9: 0x00000000022b0b67 tostring-test-lto`boost::CV::simple_exception_policy<unsigned short, (unsigned short)1, (unsigned short)12, boost::gregorian::bad_month>::on_error((null)=<unavailable>, (null)=<unavailable>, (null)=<unavailable>) at constrained_value.hpp:0
    frame #10: 0x00000000022b63e2 tostring-test-lto`yb::DateTime::TimestampFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::DateTime::InputFormat const&) [inlined] boost::CV::constrained_value<boost::CV::simple_exception_policy<unsigned short, (unsigned short)1, (unsigned short)12, boost::gregorian::bad_month> >::assign(this=<unavailable>, value=1) at constrained_value.hpp:77:9
    frame #11: 0x00000000022b63cb tostring-test-lto`yb::DateTime::TimestampFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::DateTime::InputFormat const&) [inlined] boost::CV::constrained_value<boost::CV::simple_exception_policy<unsigned short, (unsigned short)1, (unsigned short)12, boost::gregorian::bad_month> >::constrained_value(this=<unavailable>, value=1) at constrained_value.hpp:48:7
    frame #12: 0x00000000022b63cb tostring-test-lto`yb::DateTime::TimestampFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::DateTime::InputFormat const&) [inlined] boost::gregorian::greg_month::greg_month(this=<unavailable>, theMonth=1) at greg_month.hpp:59:61
    frame #13: 0x00000000022b63cb tostring-test-lto`yb::DateTime::TimestampFromString(str=<unavailable>, input_format=<unavailable>) at date_time.cc:187:28
    frame #14: 0x0000000002017948 tostring-test-lto`yb::util_test::TestDateTimeCase_TimeStampDataType_Test::TestBody(this=<unavailable>) at tostring-test.cc:290:26
    frame #15: 0x0000000002063662 tostring-test-lto`void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) [inlined] void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(object=0x00000000054001b0, method=<unavailable>, location="")(), char const*) at gtest.cc:2402:10
    frame #16: 0x0000000002063653 tostring-test-lto`void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(object=<unavailable>, method=00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00, location="")(), char const*) at gtest.cc:2438:14
    frame #17: 0x000000000206c1c2 tostring-test-lto`testing::internal::UnitTestImpl::RunAllTests() [inlined] testing::Test::Run(this=0x00000000054001b0) at gtest.cc:2474:5
    frame #18: 0x000000000206bf5d tostring-test-lto`testing::internal::UnitTestImpl::RunAllTests() [inlined] testing::TestInfo::Run(this=0x0000000004996b40) at gtest.cc:2656:11
    frame #19: 0x000000000206bdcc tostring-test-lto`testing::internal::UnitTestImpl::RunAllTests() at gtest.cc:2774:28
    frame #20: 0x000000000206bc2f tostring-test-lto`testing::internal::UnitTestImpl::RunAllTests(this=<unavailable>) at gtest.cc:4649:43
    frame #21: 0x00000000021743e5 tostring-test-lto`main [inlined] bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(object=0x0000000004998000, method=00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00, location=<unavailable>)(), char const*) at gtest.cc:2402:10
    frame #22: 0x00000000021743dd tostring-test-lto`main at gtest.cc:2438:14
    frame #23: 0x00000000021743bf tostring-test-lto`main [inlined] testing::UnitTest::Run(this=<unavailable>) at gtest.cc:4257:10
    frame #24: 0x0000000002174341 tostring-test-lto`main [inlined] RUN_ALL_TESTS() at gtest.h:2233:46
    frame #25: 0x0000000002174333 tostring-test-lto`main(argc=1, argv=0x00007ffe4e58fc58) at test_main.cc:105:13
    frame #26: 0x00007f2d53e25825 libc.so.6`__libc_start_main(main=(tostring-test-lto`main at test_main.cc:88), argc=2, argv=0x00007ffe4e58fc58, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007ffe4e58fc48) at libc-start.c:289
    frame #27: 0x0000000001fa3029 tostring-test-lto`_start + 41

Built yugabyte-db-thirdparty with this patch, off of the commit yugabyte/yugabyte-db-thirdparty@52b25a9:

diff --git a/python/yugabyte_db_thirdparty/builder.py b/python/yugabyte_db_thirdparty/builder.py
index fc3521c..db68c77 100644
--- a/python/yugabyte_db_thirdparty/builder.py
+++ b/python/yugabyte_db_thirdparty/builder.py
@@ -499,6 +499,8 @@ class Builder(BuilderInterface):
         if self.build_type == BUILD_TYPE_TSAN:
             self.compiler_flags += TSAN_FLAGS

+        self.compiler_flags.append('-g')
+
     def add_linuxbrew_flags(self) -> None:
         if using_linuxbrew():
             lib_dir = os.path.join(get_linuxbrew_dir(), 'lib')

Then built yugabyte-db off of commit f27f2a3 like so:

export YB_THIRDPARTY_DIR=$HOME/code/yugabyte-db-thirdparty
export YB_LINUXBREW_DIR=/opt/yb-build/brew/linuxbrew-20181203T161736v9
./yb_build.sh --clang13 --lto full release --linuxbrew --save-log

Created a script build-support/test_lto.sh:

#!/usr/bin/env bash

. "${BASH_SOURCE%/*}/common-build-env.sh"

activate_virtualenv
set_pythonpath

if [[ $( uname -m ) == "x86_64" ]]; then
  build_root_basename=release-clang13-linuxbrew-full-lto-ninja
else
  build_root_basename=release-clang12-full-lto-ninja
fi

set -x
"$YB_SRC_ROOT/python/yb/dependency_graph.py" \
    --build-root "$YB_SRC_ROOT/build/${build_root_basename}" \
    --file-regex "^.*/tostring-test$" \
    link-whole-program \
    "$@"

Modified a test:

diff --git a/src/yb/util/tostring-test.cc b/src/yb/util/tostring-test.cc
index b65449c..5b573cc 100644
--- a/src/yb/util/tostring-test.cc
+++ b/src/yb/util/tostring-test.cc
@@ -28,6 +28,8 @@
 #include "yb/util/monotime.h"
 #include "yb/util/tostring.h"
 #include "yb/util/uuid.h"
+#include "yb/util/date_time.h"
+#include "yb/util/result.h"

 namespace yb {
 // We should use namespace other than yb::ToString to check how does ToString works
@@ -257,5 +259,37 @@ TEST(ToStringTest, Struct) {
   ASSERT_EQ(TestClass(42, "test").ToString(), "{ a: 42 b: test }");
 }

+namespace {
+
+void ThrowEx1Func() {
+  throw std::invalid_argument("Testing exception 1");
+}
+
+void ThrowEx2Func() {
+  throw std::invalid_argument("Testing exception 2");
+}
+
+}
+
+TEST(TestDateTimeCase, ThrowException) {
+  void (*f1)() = &ThrowEx1Func;
+  void (*f2)() = &ThrowEx2Func;
+
+  try {
+    LOG(INFO) << "Calling function that will throw an exception";
+    if (rand() % 2 == 0) f1(); else f2();
+  } catch (std::invalid_argument& e) {
+    LOG(INFO) << "Caught exception: " << e.what();
+  }
+}
+
+TEST(TestDateTimeCase, TimeStampDataType) {
+  string ts_str = "2018-13-14 13:24:56.987+01:00";
+  // DateTime date_time;
+  //Timestamp ts;
+  Result<Timestamp> ts = DateTime::TimestampFromString(ts_str);
+  LOG(INFO) << "validated timestamp is: " << ts;
+}
+
 } // namespace util_test
 } // namespace yb

The test case that throws an exception in the same test works fine:

#  build/release-clang13-linuxbrew-full-lto-ninja/tests-util/tostring-test-lto --gtest_filter=TestDateTimeCase.ThrowException
Note: Google Test filter = TestDateTimeCase.ThrowException
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TestDateTimeCase
[ RUN      ] TestDateTimeCase.ThrowException
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0726 00:40:14.116119 10049 tostring-test.cc:279] Calling function that will throw an exception
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=1 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=6 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
I0726 00:40:14.116276 10049 tostring-test.cc:282] Caught exception: Testing exception 2
[       OK ] TestDateTimeCase.ThrowException (0 ms)
[----------] 1 test from TestDateTimeCase (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
00:40:14 07/26/2022 centos@

(there is some additional logging added to cxa_persionality.cc, part of libc++abi).

However, the test that attempts to catch an exception thrown from Boost, crashes:

#  build/release-clang13-linuxbrew-full-lto-ninja/tests-util/tostring-test-lto --gtest_filter=TestDateTimeCase.TimeStampDataType
Note: Google Test filter = TestDateTimeCase.TimeStampDataType
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TestDateTimeCase
[ RUN      ] TestDateTimeCase.TimeStampDataType
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=1 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=1 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=2 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=2 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
libc++abi: terminating with uncaught exception of type boost::wrapexcept<boost::gregorian::bad_month>: Month number is out of range 1..12
*** Aborted at 1658796057 (unix time) try "date -d @1658796057" if you are using GNU date ***
PC: @                0x0 (unknown)
*** SIGABRT (@0x3eb00002752) received by PID 10066 (TID 0x7f2f6f75be80) from PID 10066; stack trace: ***
    @     0x7f2f6eab60a7 __GI_raise
    @     0x7f2f6eab74aa __GI_abort
    @          0x24aa341 abort_message
    @          0x24a9faa demangling_terminate_handler()
    @          0x24a9b56 std::__terminate()
    @          0x24ac38d __cxxabiv1::scan_eh_tab()
    @          0x24abc4c __gxx_personality_v0
    @          0x2047d03 unwind_phase2
    @          0x2048846 _Unwind_Resume
    @          0x22b0b67 boost::CV::simple_exception_policy<>::on_error()
    @          0x22b63e2 yb::DateTime::TimestampFromString()
    @          0x2017948 yb::util_test::TestDateTimeCase_TimeStampDataType_Test::TestBody()
    @          0x2063662 testing::internal::HandleExceptionsInMethodIfSupported<>()
    @          0x206c1c2 testing::internal::UnitTestImpl::RunAllTests()
    @          0x21743e5 main
    @     0x7f2f6eaa3825 __libc_start_main
    @          0x1fa3029 (unknown)
Aborted (core dumped)

@mbautin
Copy link
Contributor Author

mbautin commented Jul 26, 2022

@mbautin
Copy link
Contributor Author

mbautin commented Jul 26, 2022

A test that calls std::stoi with an invalid argument also leads to a failure to catch the exception:

TEST(ToStringTest, StringToIntException) {
  std::string s = "abc";
  int i = 0;
  try {
    i = std::stoi(s);
  } catch (std::invalid_argument& e) {
    LOG(INFO) << "Caught exception in string to int conversion: " << e.what();
  }
  LOG(INFO) << "i=" << i;
}

Crashes with this stack trace:

# build/release-clang13-linuxbrew-full-lto-ninja/tests-util/tostring-test-lto --gtest_filter=ToStringTest.StringToIntException
Note: Google Test filter = ToStringTest.StringToIntException
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ToStringTest
[ RUN      ] ToStringTest.StringToIntException
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=1 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=1 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=2 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
native_exception=1 exceptionClass=4849336966747728640 kOurExceptionClass=4849336966747728640 get_vendor_and_language=18446744073709551360actions=2 _UA_CLEANUP_PHASE=2 _UA_HANDLER_FRAME=4
libc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion
*** Aborted at 1658800694 (unix time) try "date -d @1658800694" if you are using GNU date ***
PC: @                0x0 (unknown)
*** SIGABRT (@0x3eb00007257) received by PID 29271 (TID 0x7fb4e1a0be80) from PID 29271; stack trace: ***
    @     0x7fb4e0d660a7 __GI_raise
    @     0x7fb4e0d674aa __GI_abort
    @          0x24aa5d1 abort_message
    @          0x24aa23a demangling_terminate_handler()
    @          0x24a9de6 std::__terminate()
    @          0x24ac61d __cxxabiv1::scan_eh_tab()
    @          0x24abedc __gxx_personality_v0
    @          0x2047f93 unwind_phase2
    @          0x2048ad6 _Unwind_Resume
    @          0x2466c02 std::__1::stoi()
    @          0x20179cf yb::util_test::ToStringTest_StringToIntException_Test::TestBody()
    @          0x20638f2 testing::internal::HandleExceptionsInMethodIfSupported<>()
    @          0x206c452 testing::internal::UnitTestImpl::RunAllTests()
    @          0x2174675 main
    @     0x7fb4e0d53825 __libc_start_main
    @          0x1fa3029 (unknown)
Aborted (core dumped)

The debug logging lines were produced by the following code added to cxa_personality.cpp in libc++abi:

    scan_results results;
    // Process a catch handler for a native exception first.

    // Added this:
    fprintf(stderr,
            "native_exception=%d "
            "exceptionClass=%lu "
            "kOurExceptionClass=%lu "
            "get_vendor_and_language=%lu"
            "actions=%lu "
            "_UA_CLEANUP_PHASE=%lu "
            "_UA_HANDLER_FRAME=%lu"
            "\n",
            native_exception,
            exceptionClass,
            kOurExceptionClass,
            get_vendor_and_language,
            actions,
            _UA_CLEANUP_PHASE,
            _UA_HANDLER_FRAME);

    if (actions == (_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME) &&
        native_exception) {

@mbautin
Copy link
Contributor Author

mbautin commented Jul 26, 2022

Also a useful document on exception handling: https://itanium-cxx-abi.github.io/cxx-abi/exceptions.pdf

mbautin added a commit to yugabyte/llvm-project that referenced this issue Jul 28, 2022
mbautin added a commit to yugabyte/llvm-project that referenced this issue Jul 29, 2022
mbautin added a commit to yugabyte/llvm-project that referenced this issue Jul 29, 2022
@mbautin
Copy link
Contributor Author

mbautin commented Aug 1, 2022

Here are some details on the workaround:

    if (native_exception && actions == _UA_CLEANUP_PHASE) {
      // This might happen for LTO binaries. Assume there is no handler and no cleanup.
      results.reason = _URC_CONTINUE_UNWIND;
      return;
    }

It remains to be verified that all the destructors are being called correctly.

@mbautin
Copy link
Contributor Author

mbautin commented Aug 1, 2022

It does appear that the destructor gets called, added to tostring-test.cc. Built and linked as already shown in earlier comments above.

Test (with the exception being thrown inside libc++ -- this bug does not affect exceptions being thrown from the same compilation unit for some reason):


class MyClass {
 public:
  MyClass() { std::cout << "MyClass constructor called" << std::endl; }
  ~MyClass() { std::cout << "MyClass destructor called" << std::endl; }
};

TEST(ToStringTest, StringToIntException) {
  std::string s = "abc";
  int i = 0;
  try {
    MyClass a;
    i = std::stoi(s);
  } catch (std::invalid_argument& e) {
    LOG(INFO) << "Caught exception in string to int conversion: " << e.what();
  }
  LOG(INFO) << "i=" << i;
}

Output: https://gist.githubusercontent.com/mbautin/a177b3ac12817f9ac72b541ffc2d93af/raw (notice the "MyClass destructor called" line).

@mbautin
Copy link
Contributor Author

mbautin commented Aug 16, 2022

Reopening until the updated third-party dependencies are pulled into master.

@es1024
Copy link
Contributor

es1024 commented Aug 16, 2022

Third-party dependencies pulled into master with f2702bb

@es1024 es1024 closed this as completed Aug 16, 2022
samiahmedsiddiqui pushed a commit to samiahmedsiddiqui/yugabyte-db that referenced this issue Aug 16, 2022
…crash when enabling SSL

Summary:
This diff fixes a crash when enable SSL for the webserver, due to an old version
of Squeasel:

1. searching for and loading OpenSSL from the system rather than using the one bundled with
   thirdparty.

2. depending on the dynamic library exposing symbols that have been removed with OpenSSL 1.1.0
   (SSLv23_... methods, which have been replaced with a macro).

This is fixed by rebasing to a newer upstream commit, which does not require those symbols, and
which further presents the ssl_global_init flag to stop Squeasel from loading OpenSSL on its own.

This diff also adds the `webserver_private_key_file` and `webserver_private_key_password` gflags,
corresponding to the `ssl_private_key` and `ssl_private_key_password` options present in newer
versions of Squeasel.

This diff also fixes a crash when pthread_setspecific fails in libcds, by catching the exception
and forcing the worker thread to exit instead of letting it bubble up and kill the whole process.

Also pulling yugabyte/yugabyte-db-thirdparty@fc8dae1 to fix C++ exception handling in Clang-based LTO builds (yugabyte#13064).

Test Plan: `ybd --cxx_test server_webserver-test --gtest_filter WebserverSecureTest.TestIndexPage`

Reviewers: mbautin

Reviewed By: mbautin

Subscribers: cwang, sanketh, ybase, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D18419
mbautin added a commit to mbautin/yugabyte-db-thirdparty that referenced this issue Aug 23, 2022
…ugabyte#127)

The bug fix in libc++abi is needed to fix yugabyte/yugabyte-db#13064. Picking up these fixes in our LLVM branches:
- yugabyte/llvm-project@4047555 (branch: 14.0.6-yb, tag: https://github.com/yugabyte/llvm-project/releases/tag/llvmorg-14.0.6-yb-1)
- yugabyte/llvm-project@0131d8e (branch: 13.0.1-yb, tag: https://github.com/yugabyte/llvm-project/releases/tag/llvmorg-13.0.1-yb-2)
- yugabyte/llvm-project@2276446 (branch: 12.0.1-yb, tag: https://github.com/yugabyte/llvm-project/releases/tag/llvmorg-12.0.1-yb-2)

Other changes:
- Clean up Snyk integration to be more in line with the style of the rest of this codebase.
- Remove Clang 12 LTO builds, because we now only use Clang 13 or later with LTO.
- Replace the --single-compiler-type flag with --compiler-family (there is always a single compiler family, gcc or clang, in use for any given build.)
- Support building multiple build types in the same source directory. We now create subdirectories under build/ and installed/, named e.g. clang13-full-lto-x86_64, gcc11-x86_64., etc. This is disabled by default and can be enabled using the --use-per-build-subdirs flags. We will need changes to yugabyte-db's build system to understand this new directory structure.
mbautin added a commit to yugabyte/llvm-project that referenced this issue Oct 4, 2022
mbautin added a commit to yugabyte/llvm-project that referenced this issue Oct 29, 2022
mbautin added a commit to yugabyte/llvm-project that referenced this issue Nov 30, 2022
mbautin added a commit to yugabyte/llvm-project that referenced this issue Mar 28, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Apr 7, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Apr 27, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue May 11, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Jun 12, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Jun 21, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Sep 15, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Sep 22, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Oct 9, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Nov 20, 2023
mbautin added a commit to yugabyte/llvm-project that referenced this issue Mar 25, 2024
mbautin added a commit to yugabyte/llvm-project that referenced this issue Apr 16, 2024
mbautin added a commit to mbautin/llvm-project that referenced this issue Apr 30, 2024
@mbautin
Copy link
Contributor Author

mbautin commented Apr 30, 2024

New issue: #22191

mbautin added a commit to yugabyte/yugabyte-db-thirdparty that referenced this issue May 3, 2024
We were previously building Boost with C++14, and potentially also
building other dependencies with C++ standard versions other than C++20,
which is currently used across the main YugabyteDB codebase. This is a
suspected root cause of failures to catch exceptions thrown from Boost.

Relevant issues: yugabyte/yugabyte-db#22191
and yugabyte/yugabyte-db#13064. For the older
issue yugabyte/yugabyte-db#13064 a custom
workaround ( e.g. see the commit
yugabyte/llvm-project@8efd900
) was implemented in libc++abi, which will be unnecessary with this fix.

Also removing most of the Clang 16 builds (only keeping the one on
Ubuntu 20.04).
mbautin added a commit that referenced this issue May 11, 2024
…when parsing an invalid timestamp

Summary:
Fixing an issue with failing to catch an exception thrown from inside of the Boost time zone parsing code. This only appears in an LTO build.

- Updating third-party dependencies to make sure all C++ dependencies are all built with C++20.
  Previously Boost was built with C++14. This alone was insufficient for fixing the bug, but is a good thing to do anyway.
- Avoid parsing a VERIFY_RESULT expression to a function that might throw an exception. Instead, compute VERIFY_RESULT and store its return value in a local variable, and then pass that varaible to the make_shared call that might thrown an exception from its template argument class's constructor.

This diff also includes CMakeLists.txt build infrastructure changes to allow easily building a C++ unit test as a separate LTO executable.

Another related issue (#13064) -- an older occurrence of a similar error that was fixed at the time.
Jira: DB-11115

Test Plan:
Jenkins

Details of unit tests:

- New test TestSelect.testInvalidTimestampBadLexicalCast provided by @OlegLoginov (D34768)
- In date_time-test.cc there are two new tests, DateTimeTest.InvalidTimestampFromString and DateTimeTest.InvalidBoostTimeZoneFromString. DateTimeTest.InvalidTimestampFromString most closely matches the production issue. To reproduce the failure, date_time-test has to be built with LTO by uncommenting the `yb_add_lto_target(date_time-test date_time-test-lto "")` line in CMakeLists.txt.

Manual test (with the LTO build) -- provided by @OlegLoginov as well:

```
ycqlsh> create keyspace n;
ycqlsh> create table n.b(c1 int, c2 timestamp, primary key(c1));
ycqlsh> select * from n.b where c2 >= '2021-10-10 10:00:00 UTC_b';
-- Incorrect result:
NoHostAvailable
-- Correct result:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid Arguments. Invalid timestamp: bad lexical cast: source type value could not be interpreted as target
select * from n.b where c2 >= '2021-10-10 10:00:00 UTC_b';
^^^^^^
 (ql error -304)"
```

Reviewers: loginov, mihnea

Reviewed By: loginov

Subscribers: yql, ybase

Differential Revision: https://phorge.dev.yugabyte.com/D34970
svarnau pushed a commit that referenced this issue May 25, 2024
…when parsing an invalid timestamp

Summary:
Fixing an issue with failing to catch an exception thrown from inside of the Boost time zone parsing code. This only appears in an LTO build.

- Updating third-party dependencies to make sure all C++ dependencies are all built with C++20.
  Previously Boost was built with C++14. This alone was insufficient for fixing the bug, but is a good thing to do anyway.
- Avoid parsing a VERIFY_RESULT expression to a function that might throw an exception. Instead, compute VERIFY_RESULT and store its return value in a local variable, and then pass that varaible to the make_shared call that might thrown an exception from its template argument class's constructor.

This diff also includes CMakeLists.txt build infrastructure changes to allow easily building a C++ unit test as a separate LTO executable.

Another related issue (#13064) -- an older occurrence of a similar error that was fixed at the time.
Jira: DB-11115

Test Plan:
Jenkins

Details of unit tests:

- New test TestSelect.testInvalidTimestampBadLexicalCast provided by @OlegLoginov (D34768)
- In date_time-test.cc there are two new tests, DateTimeTest.InvalidTimestampFromString and DateTimeTest.InvalidBoostTimeZoneFromString. DateTimeTest.InvalidTimestampFromString most closely matches the production issue. To reproduce the failure, date_time-test has to be built with LTO by uncommenting the `yb_add_lto_target(date_time-test date_time-test-lto "")` line in CMakeLists.txt.

Manual test (with the LTO build) -- provided by @OlegLoginov as well:

```
ycqlsh> create keyspace n;
ycqlsh> create table n.b(c1 int, c2 timestamp, primary key(c1));
ycqlsh> select * from n.b where c2 >= '2021-10-10 10:00:00 UTC_b';
-- Incorrect result:
NoHostAvailable
-- Correct result:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid Arguments. Invalid timestamp: bad lexical cast: source type value could not be interpreted as target
select * from n.b where c2 >= '2021-10-10 10:00:00 UTC_b';
^^^^^^
 (ql error -304)"
```

Reviewers: loginov, mihnea

Reviewed By: loginov

Subscribers: yql, ybase

Differential Revision: https://phorge.dev.yugabyte.com/D34970
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ycql Yugabyte CQL (YCQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants