Bug 14251 - Repeated ExecuteNonQuery of sqlite3Insert/REPLACE eventually causes SIGSEGV while executing native code
Summary: Repeated ExecuteNonQuery of sqlite3Insert/REPLACE eventually causes SIGSEGV w...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Data.Sqlite ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-26 17:02 UTC by mike663
Modified: 2014-05-26 15:04 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro Project (13.42 KB, application/zip)
2013-08-26 17:02 UTC, mike663
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 14251 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description mike663 2013-08-26 17:02:37 UTC
Created attachment 4718 [details]
Repro Project

A directory traversal application that writes to a SQLite database eventually fails. A small directory doesn't provoke this behavior, but my home directory is big enough. It doesn't always fail after the same sub-directory. This example shows its failure messages after processing 1135 directories. It also fails if a filesystem database is used instead of the in-memory database is used, but it takes more wall-clock time to fail. I've included my log below and have attached the project that repros this failure.



CREATE TABLE IF NOT EXISTS 'Directory'( [Path] TEXT PRIMARY KEY NOT NULL UNIQUE, [Inode] TEXT, [TIMESTAMP] DATETIME DEFAULT CURRENT_TIMESTAMP)
REPLACE INTO 'Directory' ([Path], [Inode]) VALUES ('/Users/mwoodard', '340825');
... cut 1132 more REPLACEments ...
REPLACE INTO 'Directory' ([Path], [Inode]) VALUES ('/Users/mwoodard/Programming/Programming-3/SampleService/SampleServiceSetup', '1281306');
REPLACE INTO 'Directory' ([Path], [Inode]) VALUES ('/Users/mwoodard/Programming/Programming-3/Sandbox/Sandbox', '1226057');
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Mono.Data.Sqlite.UnsafeNativeMethods.sqlite3_prepare (intptr,intptr,int,intptr&,intptr&) <IL 0x0002a, 0xffffffff>
  at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection,string,Mono.Data.Sqlite.SqliteStatement,uint,string&) [0x00044] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs:268
  at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00019] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs:230
  at Mono.Data.Sqlite.SqliteCommand.GetStatement (int) [0x0000b] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs:264
  at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteCommand.GetStatement (int) <IL 0x00039, 0xffffffff>
  at Mono.Data.Sqlite.SqliteDataReader.NextResult () [0x000cc] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs:914
  at Mono.Data.Sqlite.SqliteDataReader..ctor (Mono.Data.Sqlite.SqliteCommand,System.Data.CommandBehavior) [0x00051] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs:89
  at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteDataReader..ctor (Mono.Data.Sqlite.SqliteCommand,System.Data.CommandBehavior) <IL 0x00021, 0xffffffff>
  at Mono.Data.Sqlite.SqliteCommand.ExecuteReader (System.Data.CommandBehavior) [0x00006] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs:539
  at Mono.Data.Sqlite.SqliteCommand.ExecuteNonQuery () [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs:568
  at TestConsole.MainClass.DB_ExecuteNonQuery (string) [0x00017] in /Users/mwoodard/Programming/AdvocatingTransparency/TestConsole/TestConsole/Program.cs:28
  at TestConsole.MainClass.Main (string[]) [0x000f3] in /Users/mwoodard/Programming/AdvocatingTransparency/TestConsole/TestConsole/Program.cs:64
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:


Debug info from gdb:

Attaching to process 43175.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ........................................ done
Reading symbols for shared libraries + done
0x90245095 in __wait4 ()
  6                                 0x902450ee in __workq_kernreturn ()
  5 "com.apple.libdispatch-manager" 0x902459ae in kevent ()
  4                                 0x902450ee in __workq_kernreturn ()
  3                                 0x90244b3e in recvfrom$UNIX2003 ()
  2                                 0x9024280e in semaphore_wait_trap ()
* 1 "com.apple.main-thread"         0x90245095 in __wait4 ()

Thread 6 (process 43175):
#0  0x902450ee in __workq_kernreturn ()
#1  0x98c7e0ac in _pthread_workq_return ()
#2  0x98c7de79 in _pthread_wqthread ()
#3  0x98c65d2a in start_wqthread ()

Thread 5 (process 43175):
#0  0x902459ae in kevent ()
#1  0x92c3ac71 in _dispatch_mgr_invoke ()
#2  0x92c3a7a9 in _dispatch_mgr_thread ()

Thread 4 (process 43175):
#0  0x902450ee in __workq_kernreturn ()
#1  0x98c7e0ac in _pthread_workq_return ()
#2  0x98c7de79 in _pthread_wqthread ()
#3  0x98c65d2a in start_wqthread ()

Thread 3 (process 43175):
#0  0x90244b3e in recvfrom$UNIX2003 ()
#1  0x98d05bbf in recv$UNIX2003 ()
#2  0x001197e0 in socket_transport_recv (buf=0xb0202f2d, len=11) at debugger-agent.c:1072
#3  0x00116061 in debugger_thread (arg=0x0) at debugger-agent.c:1462
#4  0x00283f1a in thread_start_routine (args=0x7a869a34) at wthreads.c:294
#5  0x00294201 in inner_start_thread (arg=0x7a63aa60) at mono-threads-posix.c:49
#6  0x98c7b5b7 in _pthread_start ()
#7  0x98c65d4e in thread_start ()

Thread 2 (process 43175):
#0  0x9024280e in semaphore_wait_trap ()
#1  0x0028f8fe in mono_sem_wait (sem=Cannot access memory at address 0x0
) at mono-semaphore.c:118
#2  0x0020803a in finalizer_thread (unused=0x0) at gc.c:1073
#3  0x001dede6 in start_wrapper_internal [inlined] () at :608
#4  0x001dede6 in start_wrapper (data=0x7a63a5d0) at threads.c:653
#5  0x00283f1a in thread_start_routine (args=0x7a8699b8) at wthreads.c:294
#6  0x00294201 in inner_start_thread (arg=0x7a63a620) at mono-threads-posix.c:49
#7  0x98c7b5b7 in _pthread_start ()
#8  0x98c65d4e in thread_start ()

Thread 1 (process 43175):
#0  0x90245095 in __wait4 ()
#1  0x98d05996 in waitpid$UNIX2003 ()
#2  0x000f15c2 in mono_handle_native_sigsegv (signal=11, ctx=0x15dbfe0) at mini-exceptions.c:2344
#3  0x00140ee5 in mono_arch_handle_altstack_exception (sigctx=0x15dbfe0, fault_addr=0x65726944, stack_ovf=0) at exceptions-x86.c:1135
#4  0x0004d901 in mono_sigsegv_signal_handler (_dummy=11, info=0x15dbfa0, context=0x15dbfe0) at mini.c:6556
#5  <signal handler called>
#6  0x9a0d1bc9 in sqlite3IndexKeyinfo ()
#7  0x9a0754e7 in sqlite3OpenTableAndIndices ()
#8  0x9a07260b in sqlite3Insert ()
#9  0x9a00c37b in yy_reduce ()
#10 0x9a004660 in sqlite3Parser ()
#11 0x9a002757 in sqlite3RunParser ()
#12 0x9a001f4d in sqlite3Prepare ()
#13 0x9a00198e in sqlite3LockAndPrepare ()
#14 0x9a0a0315 in sqlite3_prepare ()
#15 0x01c6879e in ?? ()
#16 0x01c678c0 in ?? ()
#17 0x01c67421 in ?? ()
#18 0x01c67184 in ?? ()
#19 0x01c670fc in ?? ()
#20 0x01c66b54 in ?? ()
#21 0x01c666fc in ?? ()
#22 0x01c66564 in ?? ()
#23 0x01c65a14 in ?? ()
#24 0x01c658c8 in ?? ()
#25 0x01c6c439 in ?? ()
#26 0x007e8d9c in ?? ()
#27 0x007e912f in ?? ()
#28 0x000574a5 in mono_jit_runtime_invoke (method=0x7a838e1c, obj=0x0, params=0xbffb6738, exc=0x0) at mini.c:6438
#29 0x0020e6ce in mono_runtime_invoke (method=0x7a838e1c, obj=0x0, params=0xbffb6738, exc=0x0) at object.c:2827
#30 0x00212c44 in mono_runtime_exec_main (method=0x7a838e1c, args=0x800798, exc=0x0) at object.c:4054
#31 0x00212fb5 in mono_runtime_run_main (method=0x7a838e1c, argc=0, argv=0xbffb6950, exc=0x0) at object.c:3678
#32 0x000c1f25 in mono_jit_exec (domain=0x7a622010, assembly=0x7a63ab00, argc=1, argv=0xbffb6950) at driver.c:955
#33 0x000c445f in mono_main (argc=4, argv=0xbffb6944) at driver.c:1014
#34 0x0004ac1e in main (argc=4, argv=0xbffb6944) at main.c:94

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Abort trap: 6

Press any key to continue...
Comment 1 Zack Gramana 2014-05-26 15:04:21 UTC
Now experiencing this when running Couchbase Lite for .NET on iOS, which uses Mono.Data.Sqlite:

    https://github.com/couchbaselabs/couchbase-lite-net/blob/master/src/Couchbase.Lite.Shared/Store/MonoSQLiteStorageEngine.cs#L217

It does use custom Sqlite collation functions:

    https://github.com/couchbaselabs/couchbase-lite-net/blob/master/src/Couchbase.Lite.Shared/Store/CouchbaseSqliteCollationFunctions.cs

Maybe the marshaled function isn't getting pinned correctly? The issue is not deterministic, so sometimes it happens right away, other times later. It also seems to happen much more frequently when on a non-UI thread, or at least not on the thread that created the SqliteConnection.