Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-11539

Fix segfault in test_prepare_mod_sort.cpp

      WT-11424 reverted the qsort tool from our own implementation to the cstdlib qsort which resulted in this bug in the unittest being picked up. Essentially the unit test is randomly generating b-tree id's, which occasionally overlap. They should never overlap, but when they do and one is a row-store b-tree and the other is a col-store b-tree we end up segmentation faulting by trying to compare the key.

      Program terminated with signal SIGSEGV, Segmentation fault.
      #0  0x00007fb61ab9eb9c in __wt_lex_compare (user_item=0x7fff71bcef78, tree_item=0x7fff71bcf1a8) at /home/lukep/work/catch2/src/include/btree_cmp_inline.h:91
      91              if (*userp != *treep) 
      (gdb) p *aopt
      $6 = {btree = 0x7fff71bcf6e8, type = WT_TXN_OP_BASIC_ROW, u = {op_row = {upd = 0x7fff71bcefa0, key = {data = 0x55e738316dcc, size = 8, mem = 0x0, memsize = 0, flags = 3}}, op_col = {upd = 0x7fff71bcefa0, recno = 94451568569804},
          ref = 0x7fff71bcefa0, truncate_col = {start = 140735101595552, stop = 94451568569804}, truncate_row = {start = {data = 0x7fff71bcefa0, size = 94451568569804, mem = 0x8, memsize = 0, flags = 0}, stop = {data = 0x3,
              size = 1908207584, mem = 0x7fb61ababc39 <__wt_epoch+69>, memsize = 140735101595664, flags = 3755068928}, mode = 1692844004}}, flags = 4294967136}
      (gdb) p *bopt
      $7 = {btree = 0x7fff71bd0480, type = WT_TXN_OP_BASIC_COL, u = {op_row = {upd = 0x7fff71bcf1d0, key = {data = 0x36, size = 94451590380384, mem = 0x55e7397e3870, memsize = 94451590380232, flags = 964515232}}, op_col = {
            upd = 0x7fff71bcf1d0, recno = 54}, ref = 0x7fff71bcf1d0, truncate_col = {start = 140735101596112, stop = 54}, truncate_row = {start = {data = 0x7fff71bcf1d0, size = 54, mem = 0x55e7397e3b60, memsize = 94451590379632,
              flags = 964573896}, stop = {data = 0x55e7397d55a0, size = 140735101596160, mem = 0x7fb61ab1c3ae <__wt_spin_unlock+46>, memsize = 94451590274256, flags = 964573296}, mode = 16777216}}, flags = 964573296}
      (gdb) p bopt->btree->type
      $8 = BTREE_COL_VAR
      (gdb) p aopt->btree->type
      $9 = BTREE_ROW
      (gdb) p aopt->btree->id
      $10 = 64
      (gdb) p bopt->btree->id
      $11 = 64
      

      I think this failure mode may also show up differently as, example [patch|wiredtiger_ubuntu2004_unittest_test_patch_40fa2c7eecfee34db0c4e4f333dca99ffaabf66a_64e6b65532f417b89630a36b_23_08_24_01_45_58]:

      [2023/08/24 01:55:06.447] /data/mci/1eb46cd78178d88ade4d626bb3e6cb92/wiredtiger/test/unittest/tests/test_prepare_mod_sort.cpp:105: FAILED:[2023/08/24 01:55:06.447]   REQUIRE( recno != 0 )
      [2023/08/24 01:55:06.447] with expansion:[2023/08/24 01:55:06.447]   0 != 0 

      Stack:

      (gdb) bt
      #0  0x00007fb61ab9eb9c in __wt_lex_compare (user_item=0x7fff71bcef78, tree_item=0x7fff71bcf1a8) at /home/lukep/work/catch2/src/include/btree_cmp_inline.h:91
      #1  0x00007fb61aba4378 in __txn_mod_compare (a=0x7fff71bcef60, b=0x7fff71bcf190) at /home/lukep/work/catch2/src/txn/txn.c:1550
      #2  0x00007fb61aba8f53 in __ut_txn_mod_compare (a=0x7fff71bcef60, b=0x7fff71bcf190) at /home/lukep/work/catch2/src/txn/txn.c:2728
      #3  0x00007fb61a2c7491 in msort_with_tmp (p=p@entry=0x7fff71bced70, b=0x7fff71bcec60, n=n@entry=12) at ./stdlib/msort.c:123
      #4  0x00007fb61a2c7992 in msort_with_tmp (n=12, b=<optimized out>, p=0x7fff71bced70) at ./stdlib/msort.c:44
      #5  __GI___qsort_r (b=<optimized out>, n=<optimized out>, s=112, cmp=<optimized out>, arg=0x0) at ./stdlib/msort.c:253
      #6  0x000055e7382d863b in (anonymous namespace)::C_A_T_C_H_T_E_S_T_8 () at /home/lukep/work/catch2/test/unittest/tests/test_prepare_mod_sort.cpp:310
      #7  0x000055e738202946 in Catch::TestInvokerAsFunction::invoke (this=0x55e7397b21c0) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:14328
      #8  0x000055e738201b65 in Catch::TestCase::invoke (this=0x55e7397cf620) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:14167
      #9  0x000055e7381fbe1a in Catch::RunContext::invokeActiveTestCase (this=0x7fff71bd1af0) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:13027
      #10 0x000055e7381fbb3f in Catch::RunContext::runCurrentTest (this=0x7fff71bd1af0, redirectedCout="", redirectedCerr="") at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:13000
      #11 0x000055e7381fa5c0 in Catch::RunContext::runTest (this=0x7fff71bd1af0, testCase=...) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:12761
      #12 0x000055e7381fd778 in Catch::(anonymous namespace)::TestGroup::execute (this=0x7fff71bd1ae0) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:13354
      #13 0x000055e7381fec20 in Catch::Session::runInternal (this=0x7fff71bd1de0) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:13560
      #14 0x000055e7381fe912 in Catch::Session::run (this=0x7fff71bd1de0) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:13516
      #15 0x000055e738240111 in Catch::Session::run<char> (this=0x7fff71bd1de0, argc=1, argv=0x7fff71bd20a8) at /home/lukep/work/catch2/build/_deps/catch2-src/single_include/catch2/catch.hpp:13238
      #16 0x000055e738215e62 in main (argc=1, argv=0x7fff71bd20a8) at /home/lukep/work/catch2/test/unittest/tests/main.cpp:20
       

      coverage-report-catch2 on code-statistics

      Host: i-09bcebb2b6a9dc481
      Project: wiredtiger
      Commit: 40fa2c7e

      Task Logs:

      coverage-report-catch2 task_log

      Logs:

      /data/mci/15fc78f3f2b7bfd1719529e3f2d6d4ee/wiredtiger/test/unittest/tests/test_prepare_mod_sort.cpp:281: FAILED:
      
      

      logs

      coverage-report-catch2 task_log

      Logs:

        SIGSEGV - Segmentation violation signal
      bash: line 6: 14562 Segmentation fault      (core dumped) PATH=/opt/mongodbtoolchain/v4/bin:$PATH WT_TOPDIR=$(git rev-parse --show-toplevel) WT_BUILDDIR=$WT_TOPDIR/cmake_build LD_LIBRARY_PATH=$WT_BUILDDIR LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libeatmydata.so test/unittest/unittests
      Program terminated with signal SIGSEGV, Segmentation fault.
      

      logs

            Assignee:
            clarisse.cheah@mongodb.com Clarisse Cheah
            Reporter:
            Xgen-BuildBaron-User xgen-buildbaron-user
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: