Forum > Database
sqlite unexpected access violations
Чебурашка:
After in another post I got no immediate suggestion, I created a test program in order to isolate the problem and I now post it here.
original post: https://forum.lazarus.freepascal.org/index.php/topic,66360.0.html
So, consider the attached zip with software and db.
I see random access violations like this:
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[10:47:02] mep@mep-development:~/tmp/2024-02-26-threads-and-db$ ./project1 Internal error unhandled 1 cycle 0: Access violationInternal error unhandled 1 cycle 1: Access violationInternal error unhandled 1 cycle 2: Access violation"SQLite3","3034001","3.34.1","libsqlite3.so","3034001"Heap dump by heaptrc unit of /home/mep/tmp/2024-02-26-threads-and-db/project1192262 memory blocks allocated : 16057951/16278136192262 memory blocks freed : 16057951/162781360 unfreed memory blocks : 0True heap size : 131072True free heap : 131072[10:53:01] mep@mep-development:~/tmp/2024-02-26-threads-and-db$ ./project1 Internal error unhandled 1 cycle 0: Access violationInternal error unhandled 1 cycle 1: Access violationInternal error unhandled 1 cycle 2: Access violationInternal error unhandled 1 cycle 3: Access violation"SQLite3","3034001","3.34.1","libsqlite3.so","3034001"Heap dump by heaptrc unit of /home/mep/tmp/2024-02-26-threads-and-db/project1192192 memory blocks allocated : 16052122/16272224192192 memory blocks freed : 16052122/162722240 unfreed memory blocks : 0True heap size : 131072True free heap : 131072
I tried also with latest sqlite 3.45.1.
I don't get what is going on, because despite the existence of multiple threads, they all work on separate databases, and connection/transaction/query objects are always created/destroyed.
Thanks for help.
TRon:
In which mode is your sqlite library compiled ? see also here
edit: btw you can set the OpenFlags property of TSQLite3Connection.
Чебурашка:
--- Quote from: TRon on February 29, 2024, 11:10:19 am ---In which mode is your sqlite library compiled ? see also here
--- End quote ---
The version shown in the post is 3.34.1, which is the one shipped with debian 11.5. I don't know exactly how they compile it but I would say that they compile with defaults from sqlite source code.
I also downloaded the latest sqlite 3.45.1 and I compiled default, only adding the debug messages.
I get same result in both cases of usage.
--- Code: Bash [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[11:21:04] mep@mep-development:~/dev/src/c/y_3rd-party/SQLite$ cat sqlite-configure.sh#!/bin/sh rm -rf sqlite-build;mkdir sqlite-build;cd sqlite-build;../sqlite/configure --enable-debugcd ..;[11:21:08] mep@mep-development:~/dev/src/c/y_3rd-party/SQLite$ cat sqlite-build.sh #!/bin/sh cd sqlite-build;make all;cd ..;[11:21:12] mep@mep-development:~/dev/src/c/y_3rd-party/SQLite$ ./sqlite-configure.sh; ./sqlite-build.sh checking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for a sed that does not truncate output... /usr/bin/sedchecking for grep that handles long lines and -e... /usr/bin/grepchecking for egrep... /usr/bin/grep -Echecking for fgrep... /usr/bin/grep -Fchecking for ld used by gcc... /usr/bin/ldchecking if the linker (/usr/bin/ld) is GNU ld... yeschecking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -Bchecking the name lister (/usr/bin/nm -B) interface... BSD nmchecking whether ln -s works... yeschecking the maximum length of command line arguments... 1572864checking whether the shell understands some XSI constructs... yeschecking whether the shell understands "+="... yeschecking for /usr/bin/ld option to reload object files... -rchecking for objdump... objdumpchecking how to recognize dependent libraries... pass_allchecking for ar... archecking for strip... stripchecking for ranlib... ranlibchecking command to parse /usr/bin/nm -B output from gcc object... okchecking how to run the C preprocessor... gcc -Echecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yeschecking for dlfcn.h... yeschecking for objdir... .libschecking if gcc supports -fno-rtti -fno-exceptions... nochecking for gcc option to produce PIC... -fPIC -DPICchecking if gcc PIC flag -fPIC -DPIC works... yeschecking if gcc static flag -static works... yeschecking if gcc supports -c -o file.o... yeschecking if gcc supports -c -o file.o... (cached) yeschecking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yeschecking whether -lc should be explicitly linked in... nochecking dynamic linker characteristics... GNU/Linux ld.sochecking how to hardcode library paths into programs... immediatechecking whether stripping libraries is possible... yeschecking if libtool supports shared libraries... yeschecking whether to build shared libraries... yeschecking whether to build static libraries... yeschecking for a BSD-compatible install... /usr/bin/install -cchecking for special C compiler options needed for large files... nochecking for _FILE_OFFSET_BITS value needed for large files... nochecking for int8_t... yeschecking for int16_t... yeschecking for int32_t... yeschecking for int64_t... yeschecking for intptr_t... yeschecking for uint8_t... yeschecking for uint16_t... yeschecking for uint32_t... yeschecking for uint64_t... yeschecking for uintptr_t... yeschecking for sys/types.h... (cached) yeschecking for stdlib.h... (cached) yeschecking for stdint.h... (cached) yeschecking for inttypes.h... (cached) yeschecking malloc.h usability... yeschecking malloc.h presence... yeschecking for malloc.h... yeschecking for fdatasync... yeschecking for gmtime_r... yeschecking for isnan... yeschecking for localtime_r... yeschecking for localtime_s... nochecking for malloc_usable_size... yeschecking for strchrnul... yeschecking for usleep... yeschecking for utime... yeschecking for pread... yeschecking for pread64... yeschecking for pwrite... yeschecking for pwrite64... yeschecking for tclsh8.7... nochecking for tclsh8.6... tclsh8.6configure: Version set to 3.45configure: Release set to 3.45.1checking for WASI SDK directory... nochecking whether to support threadsafe operation... yeschecking for library containing pthread_create... -lpthreadchecking for library containing pthread_mutexattr_init... none requiredchecking whether to support shared library linked as release mode or not... nochecking whether to use an in-ram database for temporary tables... nochecking if executables have the .exe suffix... unknownchecking for Tcl configuration... configure: WARNING: Can't find Tcl configuration definitionsconfigure: WARNING: *** Without Tcl the regression tests cannot be executed ***configure: WARNING: *** Consider using --with-tcl=... to define location of Tcl ***checking for library containing readline... nochecking for library containing tgetent... nochecking for readline in -lreadline... nochecking readline.h usability... nochecking readline.h presence... nochecking for readline.h... nochecking for /usr/include/readline.h... nochecking for /usr/include/readline/readline.h... nochecking for /usr/local/include/readline.h... nochecking for /usr/local/include/readline/readline.h... nochecking for /usr/local/readline/include/readline.h... nochecking for /usr/local/readline/include/readline/readline.h... nochecking for /usr/contrib/include/readline.h... nochecking for /usr/contrib/include/readline/readline.h... nochecking for /mingw/include/readline.h... nochecking for /mingw/include/readline/readline.h... nonot using linenoisechecking for library containing fdatasync... none requiredchecking build type... debugchecking zlib.h usability... yeschecking zlib.h presence... yeschecking for zlib.h... yeschecking for library containing deflate... -lzchecking for library containing dlopen... -ldlchecking whether to support math functions... yeschecking for library containing ceil... -lmchecking whether to support JSON functions... yeschecking whether to support MEMSYS5... nochecking whether to support MEMSYS3... nochecking whether to support FTS3... nochecking whether to support FTS4... nochecking whether to support FTS5... nochecking whether to support LIMIT on UPDATE and DELETE statements... nochecking whether to support GEOPOLY... nochecking whether to support RTREE... nochecking whether to support SESSION... noconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating sqlite3.pcconfig.status: creating sqlite_cfg.hconfig.status: executing libtool commands [...] gcc [...] -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0 -Wall -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=1 -c sqlite3.c[11:24:21] mep@mep-development:~/dev/src/c/y_3rd-party/SQLite$
TRon:
--- Quote from: Чебурашка on February 29, 2024, 11:26:03 am ---I also downloaded the latest sqlite 3.45.1 and I compiled default, only adding the debug messages.
--- End quote ---
then it seems to be on by default:
--- Quote ---
cc [...]
-D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0 -Wall -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=1 -c sqlite3.c
--- End quote ---
Forget the above, the option -DSQLITE_THREADSAFE=1 is for serialized. It needs to have the number 2. see also https://www.sqlite.org/compile.html#threadsafe
--- Quote ---I get same result in both cases of usage.
--- End quote ---
I am testing with default form my distro: 3.40.1 64 bit and have similar results. I am fiddling with openflags now.
Чебурашка:
--- Quote from: TRon on February 29, 2024, 11:10:19 am ---edit: btw you can set the OpenFlags property of TSQLite3Connection.
--- End quote ---
As I understand this is necessary when two threads use the same connection. In my case each thread uses it's own db file, connection, transaction, query.
Thanks for helping, I am going mad on this thing.
Navigation
[0] Message Index
[#] Next page