1 2 Previous Next 21 Replies Latest reply: Mar 20, 2012 9:18 AM by Laurenfoutz-Oracle RSS

    SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error

    907700
      Hi

      I am current using Berkeley DB version 5.2.36.
      I am getting the Assertion failed: db==0 || sqlite3_mutex_held(db->mutex), file ../lang/sql/generated/sqlite3.c, line 18058 error when I try to execute a 'delete from table' query.
      Please find the stack trace info

      gdb) bt
      #0 0x200000006612a1b0:0 in lwpkill+0x30 ()
      from /usr/lib/hpux32/libpthread.so.1
      #1 0x2000000066093a10:0 in pthread_kill+0x8d0 ()
      from /usr/lib/hpux32/libpthread.so.1
      #2 0x20000000658d05a0:0 in raise+0xe0 () from /usr/lib/hpux32/libc.so.1
      #3 0x20000000659f0cd0:0 in abort+0x170 () from /usr/lib/hpux32/libc.so.1
      #4 0x200000006589b730:0 in _assert+0x260 () from /usr/lib/hpux32/libc.so.1
      #5 0x20000000664b4480:0 in sqlite3DbMallocRaw+0xe0 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #6 0x2000000066505070:0 in sqlite3VdbeRecordUnpack+0x130 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #7 0x2000000066504470:0 in btreeCompare+0x830 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #8 0x2000000066505cf0:0 in btreeCompareShared+0xe0 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #9 0x2000000066c0b1f0:0 in __db_moff+0x280 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #10 0x20000000666b4f70:0 in __bam_cmp+0x8e0 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #11 0x2000000066774640:0 in __bam_search+0x1400 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #12 0x20000000666f0060:0 in __bamc_physdel+0x1a20 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      ---Type <return> to continue, or q <return> to quit---
      #13 0x20000000666e27a0:0 in __bamc_close+0x1550 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #14 0x2000000066b6d9f0:0 in __dbc_close+0xa50 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #15 0x2000000066bd3390:0 in __dbc_close_pp+0xd80 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #16 0x200000006651b140:0 in sqlite3BtreeDelete+0xab0 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #17 0x2000000066594050:0 in sqlite3VdbeExec+0x27050 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #18 0x200000006656c650:0 in sqlite3Step+0x870 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #19 0x2000000066499370:0 in sqlite3_step+0x150 ()
      from /scm/vobs/stgFINPI/rpconv/bdb/lib/HPUX_IA_1131/libdb_sql-5.2.so
      #20 0x400ad20:0 in exec () at testCounter.cpp:71
      #21 0x4014490:0 in truncate () at testCounter.cpp:348
      #22 0x200000006605abc0:0 in __pthread_bound_body+0x190 ()
      from /usr/lib/hpux32/libpthread.so.1

      A sample code to reproduce the above error can also be provided if required.

      Thanks
        • 2. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
          Oracle, Sandra Whitman
          Hello,

          Yes, please provide a standalone test case that can be run to reproduce the problem. If it is too long to post here, please send it to me via email at sandra.whitman @ <this company> . com.

          Thanks,
          Sandra
          • 3. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
            689065
            We also encounter this only when the BDB sql libaries are configured and compiled with the --enable-debug option.
            From the statement it looks like it can throw an error if the db handle is null or if the mutex is held.
            Is the assert statement correct in this place?
            • 4. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
              Oracle, Sandra Whitman
              Hello,

              Yes --enable-debug turns the assertion on.  Basically the assert in sqlite3DbMallocRaw()
              is ensuring that a mutex exists before the allocation. Internally memory is allocated as
              one buffer in the db object with parts of the buffer assigned to objects as needed.
              The mutex must be present to ensure that two threads do not get assigned the same
              part of the buffer.


              Thanks,
              Sandra
              • 5. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                907700
                Did the code help reproduce the problem?

                Thanks
                • 6. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                  Oracle, Sandra Whitman
                  Hello,

                  I ran the test this morning in 5.2.36 several times (after correcting some compilation/etc. issues), but
                  otherwise leaving the test unchanged, and am invoking it with:

                  ./test x
                  where I tried an x of 10, 20, 30

                  I have not hit the assert yet.

                  I bujilt the library as:
                  ./dist/configure enable-debug enable-diagnostic enable-cxx enable-sql_compat


                  Is there anything else I should be doing to see the assertion? How long does the test typically
                  run before hitting it?

                  Thanks,
                  Sandra
                  • 7. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                    Oracle, Sandra Whitman
                    Actually on trying again I am noticing:
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:6 erno
                    Deleted ::::::::::::::: 54
                    writing........55
                    ERROR: AsserFailTest: statement aborts at 27: [insert into ctable values(550,'55','xxxxx','550','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

                    It would be better to have a test that only reproduces the one assert in question
                    SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error

                    Please verify that I am running the test in a way to get the reported assert.


                    Thanks,
                    Sandra                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                    • 8. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                      user11188564
                      Sandra,thanks for you help. Will send you the updated program - looking at the code we think the problem is in -

                      The function static int btreeCompare

                      The following code picks up keyinfo from the linklist -

                                     for (pCur = pBt->first_cursor;
                                     pCur != NULL;
                                     pCur = pCur->next)
                                          if (pCur->tableIndex == iTable)
                                               break;

                                     assert(pCur);
                                     keyInfo = pCur->keyInfo;

                      There is no check for the threadid - this structure is shared by all threads of the process - Subsequent the assert fails in

                      sqlite3DbMallocRaw which is called from sqlite3VdbeRecordUnpack

                      because the DB handle belongs to a different thread -the lock owner check fails.

                      Appreciate if you let us know - if our analysis is correct & a potential fix.
                      • 9. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                        918889
                        I have not hit the assert yet.

                        I bujilt the library as:
                        ./dist/configure enable-debug enable-diagnostic enable-cxx enable-sql_compat

                        Is there anything else I should be doing to see the assertion? How long does the test typically
                        run before hitting it?
                        -------------------------------------------------------------------------------------------------
                        mother of the bride dresses

                        Edited by: 915886 on Feb 21, 2012 1:52 AM
                        • 10. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                          907700
                          Hi Sandra,

                          I have built the library using enable_debug enable_sql.

                          Also please increase the number of records to 200+. The point at which we hit assertion failed is not consistent, hence I am unable to tell when exactly the condition is reached.

                          Please comment out the print statement in the errLog function so that there is no other error printed.

                          void errLog(void tmp,int errNo, const char* errMsg)
                          {

                          // printf("ERROR: %s: %s:%d erno\n",(char*)tmp, errMsg, errNo);
                          }

                          In a 200 records test case I hit the condition in 1-5th iteration in most cases. At 100 records test case I hit the conditions much later between 30-50th iterations.

                          I am trying to update the code to make it reach the condition earlier.

                          Thanks
                          Sandeep.
                          • 11. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                            Oracle, Sandra Whitman
                            Thanks,

                            I was able to reproduce this now:
                            Starting the program..
                            !!!!1!!!
                            writing........0
                            writing........1
                            test: ../lang/sql/generated/sqlite3.c:18058: sqlite3DbMallocRaw: Assertion `db==0 || sqlite3_mutex_held(db->mutex)' failed.
                            Aborted (core dumped)


                            Sandra
                            • 12. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                              907700
                              Hi Sandra,

                              Any updates on the issue?

                              Thanks
                              • 13. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                                Oracle, Sandra Whitman
                                Hi Sandeep, Rittick,

                                Yes since we can reproduce the assert we are working on it now.
                                I will let you know when we have a resolution.


                                Thanks,
                                Sandra
                                • 14. Re: SQLite: Assertion failed: db==0 || sqlite3_mutex_held(db->mutex) error
                                  user11188564
                                  Sandra,
                                  Any updates. What is the potential impact of this bug ? Appreciate a response.

                                  thank you.
                                  1 2 Previous Next