SQLite becomes locked while opening connection
Posted: Mon  20 Jul 2015 16:02
				
				I am using SQLite 5.2.437.0 in a C# application (.NET v4.0.30319) which reads/writes to a SQLite database and can run for several days as it processes files. Since upgrading to 5.2.437.0, the thread accessing the SQLite database will become locked after running for a day or so. The other threads in the application appear to be running normally. I created a memory dump and, using WinDbg, I saw the locked thread was within a SQLite method (see callstack below). The thread remains locked until the process is killed. Any suggestions on what is causing this and how to resolve it?
----------------------------------------------------------------------------------------------------
WinDbg:
Current frame: ntdll!ZwWaitForSingleObject+0x15
ChildEBP RetAddr Caller, Callee
16b3e914 76fa9e5e ntdll!RtlpWaitOnCriticalSection+0x13e, calling ntdll!NtWaitForSingleObject
16b3e940 741611a5 clr!WKS::GCHeap::WhichGeneration+0xb, calling clr!WKS::gc_heap::object_gennum
16b3e948 73fd4e7f clr!HndWriteBarrier+0x15
16b3e958 73fd9cf2 clr!HndCreateHandle+0xf1, calling clr!_EH_epilog3
16b3e978 76fa9d42 ntdll!RtlEnterCriticalSection+0x150, calling ntdll!RtlpWaitOnCriticalSection
16b3e9a0 100039ad sqlite3!sqlite3_mutex_leave+0x1dd, calling ntdll!RtlEnterCriticalSection
16b3e9ac 10057dbe sqlite3!sqlite3_reset_auto_extension+0x420e, calling sqlite3!sqlite3_mutex_leave+0x1d0
16b3e9c8 10057f40 sqlite3!sqlite3_prepare_v2+0x20, calling sqlite3!sqlite3_reset_auto_extension+0x41d0
16b3e9ec 0b47ff6b (MethodDesc 0b4c9044 +0x73 DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, Int32, IntPtr ByRef, IntPtr ByRef))
16b3ea18 0b47ff6b (MethodDesc 0b4c9044 +0x73 DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, Int32, IntPtr ByRef, IntPtr ByRef))
16b3ea3c 0b47fd5d (MethodDesc 0ae89a38 +0x85 Devart.Data.SQLite.a6.a(System.String, UInt32, System.String ByRef)), calling 0abc8c18
16b3ea4c 731520bc (MethodDesc 72f01774 +0x9c System.Text.StringBuilder.Append(System.String)), calling (MethodDesc 72fd0188 +0 System.Buffer.Memcpy(Byte*, Byte*, Int32))
16b3eaac 0b47f75a (MethodDesc 0b4c4dcc +0x22 Devart.Data.SQLite.bq.p()), calling (MethodDesc 0ae89a38 +0 Devart.Data.SQLite.a6.a(System.String, UInt32, System.String ByRef))
16b3eac0 0b47f5bf (MethodDesc 0ae8a264 +0x4f Devart.Data.SQLite.ag.e()), calling (MethodDesc 0b4c4dcc +0 Devart.Data.SQLite.bq.p())
16b3ead8 0b47d5cb (MethodDesc 0ae89018 +0x7b3 Devart.Data.SQLite.p.h()), calling (MethodDesc 0ae8a264 +0 Devart.Data.SQLite.ag.e())
16b3ecdc 73ff4315 clr!WeakReferenceNative::Create+0x1a8, calling clr!_EH_epilog3
16b3ecf0 0b47beb6 (MethodDesc 0ae8903c +0xe Devart.Data.SQLite.p.b()), calling (MethodDesc 0ae89018 +0 Devart.Data.SQLite.p.h())
16b3ecfc 0b478ed1 (MethodDesc 0ae9aaec +0x139 Devart.Common.DbConnectionFactory.b(Devart.Common.DbConnectionBase))
16b3ed3c 0b478b50 (MethodDesc 0ae9f03c +0x60 Devart.Common.DbConnectionClosed.Open(Devart.Common.DbConnectionBase)), calling (MethodDesc 0ae9aaec +0 Devart.Common.DbConnectionFactory.b(Devart.Common.DbConnectionBase))
16b3ed64 0b478816 (MethodDesc 0ae9a0c8 +0xae Devart.Common.DbConnectionBase.Open())
16b3ed98 0b478387 (MethodDesc 0ae9a5c0 +0x2f Devart.Data.SQLite.SQLiteConnection.Open()), calling (MethodDesc 0ae9a0c8 +0 Devart.Common.DbConnectionBase.Open())
16b3edb8 0b47826c (MethodDesc 0ad735fc +0xcc SqlHelper.open(System.Data.Common.DbConnection))
			----------------------------------------------------------------------------------------------------
WinDbg:
Current frame: ntdll!ZwWaitForSingleObject+0x15
ChildEBP RetAddr Caller, Callee
16b3e914 76fa9e5e ntdll!RtlpWaitOnCriticalSection+0x13e, calling ntdll!NtWaitForSingleObject
16b3e940 741611a5 clr!WKS::GCHeap::WhichGeneration+0xb, calling clr!WKS::gc_heap::object_gennum
16b3e948 73fd4e7f clr!HndWriteBarrier+0x15
16b3e958 73fd9cf2 clr!HndCreateHandle+0xf1, calling clr!_EH_epilog3
16b3e978 76fa9d42 ntdll!RtlEnterCriticalSection+0x150, calling ntdll!RtlpWaitOnCriticalSection
16b3e9a0 100039ad sqlite3!sqlite3_mutex_leave+0x1dd, calling ntdll!RtlEnterCriticalSection
16b3e9ac 10057dbe sqlite3!sqlite3_reset_auto_extension+0x420e, calling sqlite3!sqlite3_mutex_leave+0x1d0
16b3e9c8 10057f40 sqlite3!sqlite3_prepare_v2+0x20, calling sqlite3!sqlite3_reset_auto_extension+0x41d0
16b3e9ec 0b47ff6b (MethodDesc 0b4c9044 +0x73 DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, Int32, IntPtr ByRef, IntPtr ByRef))
16b3ea18 0b47ff6b (MethodDesc 0b4c9044 +0x73 DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, Int32, IntPtr ByRef, IntPtr ByRef))
16b3ea3c 0b47fd5d (MethodDesc 0ae89a38 +0x85 Devart.Data.SQLite.a6.a(System.String, UInt32, System.String ByRef)), calling 0abc8c18
16b3ea4c 731520bc (MethodDesc 72f01774 +0x9c System.Text.StringBuilder.Append(System.String)), calling (MethodDesc 72fd0188 +0 System.Buffer.Memcpy(Byte*, Byte*, Int32))
16b3eaac 0b47f75a (MethodDesc 0b4c4dcc +0x22 Devart.Data.SQLite.bq.p()), calling (MethodDesc 0ae89a38 +0 Devart.Data.SQLite.a6.a(System.String, UInt32, System.String ByRef))
16b3eac0 0b47f5bf (MethodDesc 0ae8a264 +0x4f Devart.Data.SQLite.ag.e()), calling (MethodDesc 0b4c4dcc +0 Devart.Data.SQLite.bq.p())
16b3ead8 0b47d5cb (MethodDesc 0ae89018 +0x7b3 Devart.Data.SQLite.p.h()), calling (MethodDesc 0ae8a264 +0 Devart.Data.SQLite.ag.e())
16b3ecdc 73ff4315 clr!WeakReferenceNative::Create+0x1a8, calling clr!_EH_epilog3
16b3ecf0 0b47beb6 (MethodDesc 0ae8903c +0xe Devart.Data.SQLite.p.b()), calling (MethodDesc 0ae89018 +0 Devart.Data.SQLite.p.h())
16b3ecfc 0b478ed1 (MethodDesc 0ae9aaec +0x139 Devart.Common.DbConnectionFactory.b(Devart.Common.DbConnectionBase))
16b3ed3c 0b478b50 (MethodDesc 0ae9f03c +0x60 Devart.Common.DbConnectionClosed.Open(Devart.Common.DbConnectionBase)), calling (MethodDesc 0ae9aaec +0 Devart.Common.DbConnectionFactory.b(Devart.Common.DbConnectionBase))
16b3ed64 0b478816 (MethodDesc 0ae9a0c8 +0xae Devart.Common.DbConnectionBase.Open())
16b3ed98 0b478387 (MethodDesc 0ae9a5c0 +0x2f Devart.Data.SQLite.SQLiteConnection.Open()), calling (MethodDesc 0ae9a0c8 +0 Devart.Common.DbConnectionBase.Open())
16b3edb8 0b47826c (MethodDesc 0ad735fc +0xcc SqlHelper.open(System.Data.Common.DbConnection))