Sqlite-net: SIGSEGV

Created on 27 May 2013  路  5Comments  路  Source: praeclarum/sqlite-net

I would like to understand why the next crash is happening.

Important:
I cannot reproduce it. My unit tests are Ok, but after using the application for a while (hours or even days), the next crash happens again.

Logs are from Crashlytics:

Exception Type: SIGSEGV Code: SEGV_ACCERR at 0x2
Thread Crashed
5/26/2013 at 17:38:49 UTC-0300
0    libsqlite3.dylib    sqlite3_step + 42265
1       
2    libsqlite3.dylib    sqlite3_value_text + 2766
3    libsqlite3.dylib    sqlite3_step + 30818
4    libsqlite3.dylib    sqlite3_step + 2142
5    SampleIOS   wrapper_managed_to_native_SQLite3_Step_intptr
6    SampleIOS   System_Collections_Generic_List_1_AddEnumerable_System_Collections_Generic_IEnumerable_1_T
7    SampleIOS   System_Collections_Generic_List_1__ctor_System_Collections_Generic_IEnumerable_1_T
8    SampleIOS   System_Linq_Enumerable_ToList_TSource_System_Collections_Generic_IEnumerable_1_TSource
9    SampleIOS   SQLiteCommand_ExecuteQuery_T

And here is the code which is generating the exception:

IEnumerable<Message> results = database.ExecuteQueryWithLambda<Message> (
() =>
from message in database.Table<Message> ()
where (
message.ConversationID == conversationID && 
message.UserAccountID == userAccountID &&
message.SentDate != null &&
message.DeliveredToRecipientDate != null
)
select message)
.OrderByDescending (message => message.SentDate)
    .Take<Message> (1)
    .ToList<Message> ();
public IEnumerable<T> ExecuteQueryWithLambda<T> (Func<IEnumerable<T>> query) where T : new ()
{
    lock (locker) {
        try {
            return query.Invoke ();
        } catch (Exception ex) {
            //
            // Log
            Logger.Log ("SQLiteDatabase 'ExecuteQueryWithLambda' caught an Exception: {0}", ex);
            return new List<T> ();
        }
    }
}

Note:
I have just tried to catch the exception but the app still crashing before the catch block gets called.

I would appreciate for any help. I cannot understand what is the real problem. Is there something wrong with my ExecuteQueryWithLambda method implementation?

I am using:

  • A Mac;
  • Xamarin Studio;
  • Xamarin.iOS;

Thanks.

Question

All 5 comments

I have the same issue

I think I could fix this issue by forcing the database to work in a serialized way.

During the initialisation of yours SQLiteConnection subclass, add the next configuration:

SQLite3.Config (SQLite3.ConfigOption.Serialized);

This option sets the threading mode to Serialized. In other words, this option enables all mutexes including the recursive mutexes on database connection and prepared statement objects. In this mode the SQLite library will itself serialize access to database connections and prepared statements so that the application is free to use the same database connection or the same prepared statement in different threads at the same time.
(Source: http://sqlite.org/c3ref/c_config_getmalloc.html)

After defining the Serialized option I could never see the SIGSEGV error again.

Hopefully it may work for you too.

Sorry, but Crashlytics still reporting the same SIGSEGV exceptions.
The previous workaround does not work at all.
I need some help here. Thanks.

Hi,
Yes, you need to call sqllite_shutdown() and then set to serialized mode, followed by initalize(), see my pull request https://github.com/praeclarum/sqlite-net/pull/220

I'm closing this since it looks like you got an answer.

Was this page helpful?
0 / 5 - 0 ratings