nefarius / Nefarius.HttpClient.LiteDbCache

Adds disk-based response caching to HttpClient named instances using LiteDB.
MIT License
1 stars 0 forks source link

DB Needs to be protected by a lock or mutex or alike #2

Closed Paliverse closed 9 months ago

Paliverse commented 9 months ago

Possible Causes:

https://github.com/nefarius/Nefarius.HttpClient.LiteDbCache/blob/37f531954f246d4671347236c0e15072c97b767d/src/Internal/CacheDatabaseInstances.cs#L21

https://github.com/nefarius/Nefarius.HttpClient.LiteDbCache/blob/37f531954f246d4671347236c0e15072c97b767d/src/Internal/LiteDbCacheHandler.cs#L59

Exception:

System.IO.IOException: The process cannot access the file 'C:\Program Files (x86)\Steam\steamapps\common\DSX\Main_v3_Beta\caches\internet-availability.db' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at LiteDB.Engine.FileStreamFactory.GetStream(Boolean canWrite, Boolean sequencial)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at LiteDB.Engine.DiskService..ctor(EngineSettings settings, Int32[] memorySegmentSizes)
   at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings)
   at LiteDB.ConnectionString.CreateEngine()
   at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)
   at Nefarius.HttpClient.LiteDbCache.Internal.CacheDatabaseInstances.GetDatabase(String name)
   at Nefarius.HttpClient.LiteDbCache.Internal.LiteDbCacheHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at DSX.Core.HttpClientFactoryExtensions.<>c__DisplayClass3_0.<<HasInternetConnectivity>b__0>d.MoveNext()
nefarius commented 9 months ago

Protective lock included in release Version 1.6.0