C# SQLite 3.7.7.1 and Multithreading Issues

256 views
Skip to first unread message

Mike Nicolino

unread,
Dec 13, 2012, 8:09:40 PM12/13/12
to csharp...@googlegroups.com
Using SQLite v3.7.7.1, very rarely, I'm getting some odd errors/exceptions occurring that appear to be multi-threading issues when executing queries (select ...).  Our setup uses pooled database connections (sqlite3 objects) for threads; there is no cross thread sharing. There's also no physical database; we exclusively use modules/virtual tables to query data from other sources (no inserts or updates). I've seen the following errors:

1. System.ArgumentException: Offset and length were out of bounds at CsharpSqlite.Sqlite3.balance_nonroot(MemPage pParent, Int32 iParentIdx, Byte[] aOvflSpace, Int32 isRoot).
2. Return code of SQLITE_CORRUPT for the query.
3. In a staged test (firing off 3 queries simultaneously via Parallel.Foreach), getting a debug assert: Debug.Assert( scratchAllocOut >= 1 && scratchAllocOut <= 2 ) in CsharpSqlite.Sqlite3.sqlite3ScratchFree(byte[] p) (the scratchAlloc out variable is 0).

The 1st 2 errors I've never seen outside of a loaded environment and are very rare (have not been able to catch them in debugger).  The 3rd I can reproduce fairly consistently in my test case.  Has anyone else encountered similar issues using SQLite3 in a multi-threaded app or have any suggestions about what might be going on?

Other details (fixed locally):
- The InitializeCriticalSection() and DeleteCriticalSection() methods in _Custom.cs were entering/exiting the specified mutex, locking it on creation.
- The winMutexLeave on mutex_w32.cs was not handling recursive mutexes, It was only leaving the mutex when the ref count hit 0 (but entering it every time).

Any input much appreciated.
Thanks!
Reply all
Reply to author
Forward
0 new messages