Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentOutOfRangeException in SqliteConnectionFactory.PruneCallback #29952

Closed
BioTurboNick opened this issue Dec 31, 2022 · 10 comments · Fixed by #30080
Closed

ArgumentOutOfRangeException in SqliteConnectionFactory.PruneCallback #29952

BioTurboNick opened this issue Dec 31, 2022 · 10 comments · Fixed by #30080
Labels
area-adonet-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@BioTurboNick
Copy link

This was reported by Microsoft AppCenter on a running device in the wild, but the stack trace does not contain any of my user code.

Xamarin Exception Stack:
System.ArgumentOutOfRangeException: ArgumentOutOfRange_IndexMustBeLess Arg_ParamName_Name, index
  at System.Collections.Generic.List`1[[Microsoft.Data.Sqlite.SqliteConnectionPoolGroup, Microsoft.Data.Sqlite, Version=7.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].get_Item(Int32 )
  at Microsoft.Data.Sqlite.SqliteConnectionFactory.PruneCallback(Object _)
  at System.Threading.TimerQueueTimer.<>c.<.cctor>b__27_0(Object )
  at System.Threading.ExecutionContext.RunInternal(ExecutionContext , ContextCallback , Object )
  at System.Threading.ExecutionContext.RunInternal(ExecutionContext , ContextCallback , Object )
  at System.Threading.TimerQueueTimer.CallCallback(Boolean )
  at System.Threading.TimerQueueTimer.Fire(Boolean )
  at System.Threading.TimerQueue.FireNextTimers()
  at System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
  at System.Threading.ThreadPoolWorkQueue.Dispatch()
  at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
  at System.Threading.Thread.StartCallback()

Microsoft.Data.Sqlite version: 7.0.1
Target framework: .NET 7.0
Operating system: Android 12

I'm guessing there needs to be a lock around _idlePoolGroups usage?

@FM1973
Copy link

FM1973 commented Jan 3, 2023

I got the same exception from time to time.
Android 11+ as well as IOS 14+

@ajcvickers
Copy link
Contributor

/cc @bricelam

@FM1973
Copy link

FM1973 commented Jan 10, 2023

Is there anything we can do as a workaround? Our testers (app) get this exception at least once or twice a day which crashes the app.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 10, 2023

@FM1973 maybe disable connection pooling?

@FM1973
Copy link

FM1973 commented Jan 10, 2023

@ErikEJ
Thanks for your suggestion.
How can I disable pooling when using "UseSqlite" like this:
builder.Services.AddDbContext<LocalDbContext>(o => o.UseSqlite($"Filename={databasePath}", sqlLiteOptions => { sqlLiteOptions.CommandTimeout(120);}));

I can´t find a property for disabling pooling on the options builder.

I´m sure this can be easily done, but I´m too dumb finding it :)

@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 10, 2023

@FM1973 Just read the manual: https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/connection-strings#pooling

 o.UseSqlite($"Filename={databasePath};Pooling=false"

@FM1973
Copy link

FM1973 commented Jan 10, 2023

@ErikEJ
Heck... I´m sorry. Thanks a lot!

@ajcvickers ajcvickers added this to the 8.0.0 milestone Jan 12, 2023
@FM1973
Copy link

FM1973 commented Jan 12, 2023

Ok, disabling the connection pool doesn´t help.
The same error still occurs.

@symbiogenesis
Copy link

I'm seeing this as well. Also using 7.0.1 on Android.

Maybe rolling back to 7.0.0 is the workaround.

@ajcvickers
Copy link
Contributor

Note from triage: bring to Tactics for servicing.

dougbu pushed a commit that referenced this issue Feb 7, 2023
…ack (#30098)

* Move taking of lock earlier to avoid race in PruneCallback
  * Fixes #29952
* Add quirk
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Feb 9, 2023
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-adonet-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants