SQLite becomes locked while opening connection

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
steved
Posts: 9
Joined: Mon 15 Jun 2015 14:49

SQLite becomes locked while opening connection

Post by steved » 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))

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: SQLite becomes locked while opening connection

Post by Pinturiccio » Wed 22 Jul 2015 10:40

steved wrote:Since upgrading to 5.2.437.0
What version of dotConnect for SQLite did you use before (i.e. the one, where the issue was not being reproduced)?

Basing on the provided error, we consider that the lock takes place during query execution. SQLite returns us that the file is locked and we wait for the file unlock till the time that is specified in the CommandTimeout property runs out. When the time is up, the error is generated. Try increasing the CommandTimeout value.

steved
Posts: 9
Joined: Mon 15 Jun 2015 14:49

Re: SQLite becomes locked while opening connection

Post by steved » Wed 22 Jul 2015 18:22

I was using 5.2.422.0. The command timeout is set to 0 (no timeout). I want to point out that a query has not been executed yet. A connection is being opened.

steved
Posts: 9
Joined: Mon 15 Jun 2015 14:49

Re: SQLite becomes locked while opening connection

Post by steved » Wed 22 Jul 2015 18:33

Some additional info:
I had another SQLite/dotConnect issue (see http://forums.devart.com/viewtopic.php? ... 50#p110150) that was fixed and the reason why I upgraded to the new version.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: SQLite becomes locked while opening connection

Post by Pinturiccio » Thu 23 Jul 2015 11:44

The default value of the CommandTimeout property is 30. Our documentation says that the default value is 0, but this is a mistake, and we will fix it. If you use the default value, it is equal to 30.

According to your call stack, the error occurs before executing a command. Try setting CommandTimeout value greater then 30 or equal to zero manually.

steved
Posts: 9
Joined: Mon 15 Jun 2015 14:49

Re: SQLite becomes locked while opening connection

Post by steved » Wed 23 Sep 2015 21:11

Do you have any other suggestions on what could be causing this or how to work around it? I have received several more reports from customers who are running into this issue. It seems to occur when there are multiple processes on the same machine accessing the SQLite database.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: SQLite becomes locked while opening connection

Post by Pinturiccio » Thu 24 Sep 2015 14:37

Please tell us when exactly the error occurs: when opening a connection, or in some other case?

1. If an error occurs when opening a connection, as you have written before and according to the call stack, then:
- Increase the "Default Command Timeout" connection string parameter value or set it to 0. For more information, please refer to https://www.devart.com/dotconnect/sqlit ... meout.html
- provide your connection string (roughly, without credentials)
- Try setting "Pooling=false" in the connection string
- Try setting "Validate Connection=true;" in the connection string. For more information, please refer to https://www.devart.com/dotconnect/sqlit ... ction.html

2. If an error occurs in some other place, this means that you sent us a wrong call stack. Tell us when the error occurs and send us the message and stack trace of the exception and all inner exceptions.

Post Reply