You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version
LiteDB 5.0.12, .NET 4.7.2, Win11 Pro 64bit.
Describe the bug
When running Linq operation Find on ILiteDatabase's FileStorage object, I'm facing an intermittent issue of it getting stuck waiting on a different thread. I'm using a Read-only connection. Multiple threads access the same file but majority of them access it in Read-only mode. Writes are not very frequent.
After that, killing the app and re-opening the app also leads to the same issue and it's reproducible beyond that. I'm guessing maybe the file handle might not be released?
The LiteDatabase instance is created with a "using". But the LiteFileInfo objects that are extracted from the FileStorage using Linq are used by MyDataModel. Is that causing the shared engine to lock and not allow new threads to access the file? Or is there something else wrong in the way I'm accessing LiteDb? Given that this is synchronous, is there a way to add a timeout to avoid getting the thread stuck for too long? I see the ILiteDatabase has a Timeout property which according to the docs is during transactions so I'm not sure it will help here.
I found a couple of similar but not exactly the same bugs - #1839, #1538. Not sure if they have the same underlying reason for the behavior.
Code to Reproduce
// Connection string keys and values are case-insensitive.
const MyCacheFileName = "...";
public IEnumerable<MyDataModel> GetCache(string filter, string expectedValue)
{
var bsonMapper = ....;
using ILiteDatabase liteDb = new LiteDatabase(
new ConnectionString
{
Filename = MyCacheFileName,
Connection = ConnectionType.Shared,
ReadOnly = true,
}, bsonMapper);
if (liteDb == null)
{
return Enumerable.Empty<MyDataModel>();
}
IEnumerable<MyDataModel> entries = liteDb.FileStorage?
.Find(f => f.Metadata["xyz"] == filter ) // ************************* STUCK HERE *******************
.Where(f => ....)
.Select(f => new MyDataModel(f));
return entries;
}
// Caller
var cachedValues = GetCache(filter: "filter1", expectedValue: "val1");
if (!cachedVals.Any())
{
cachedValues = GetCache(filter: "filter2", expectedValue: "val1");
}
// MyDataModel
public class MyDataModel
{
public MyDataModel(LiteFileInfo<string> fileInfo)
{
this.FileInfo = fileInfo;
}
public LiteFileInfo<string> FileInfo { get; }
}
Expected behavior
Doesn't get stuck and returns control back to the caller. This is what happens when this bug doesn't occur and things work fine.
Screenshots/Stacktrace
Found an interesting exception which I think may be causing this. Looks like LiteDb is unable to dispose the Read-Only DB because it doesn't have write permissions. This looks to be the same as this bug #2200.
I still don't know why this happens only sometimes and not every time though.
Exception: Stream does not support writing.;
at System.IO.FileStream.WriteSpan(ReadOnlySpan`1) + 0x4b9
at System.IO.FileStream.Write(Byte[], Int32, Int32) + 0x13a
at LiteDB.Engine.DiskService.Write(IEnumerable`1, FileOrigin) + 0x371
at LiteDB.Engine.WalIndexService.CheckpointInternal() + 0x406
at LiteDB.Engine.WalIndexService.TryCheckpoint() + 0x59
at LiteDB.Engine.LiteEngine.Dispose(Boolean) + 0x4b
at LiteDB.SharedEngine.Dispose() + 0x1e
at LiteDB.LiteDatabase.Dispose() + 0x21
at MyClass.GetCache(String, String) + 0x7a9
This is from a Windows process dump where this thread is shown to be hung.
Version
LiteDB 5.0.12, .NET 4.7.2, Win11 Pro 64bit.
Describe the bug
When running Linq operation Find on ILiteDatabase's FileStorage object, I'm facing an intermittent issue of it getting stuck waiting on a different thread. I'm using a Read-only connection. Multiple threads access the same file but majority of them access it in Read-only mode. Writes are not very frequent.
After that, killing the app and re-opening the app also leads to the same issue and it's reproducible beyond that. I'm guessing maybe the file handle might not be released?
The LiteDatabase instance is created with a "using". But the LiteFileInfo objects that are extracted from the FileStorage using Linq are used by
MyDataModel
. Is that causing the shared engine to lock and not allow new threads to access the file? Or is there something else wrong in the way I'm accessing LiteDb? Given that this is synchronous, is there a way to add a timeout to avoid getting the thread stuck for too long? I see the ILiteDatabase has a Timeout property which according to the docs is during transactions so I'm not sure it will help here.I found a couple of similar but not exactly the same bugs - #1839, #1538. Not sure if they have the same underlying reason for the behavior.
Code to Reproduce
Expected behavior
Doesn't get stuck and returns control back to the caller. This is what happens when this bug doesn't occur and things work fine.
Screenshots/Stacktrace
Found an interesting exception which I think may be causing this. Looks like LiteDb is unable to dispose the Read-Only DB because it doesn't have write permissions. This looks to be the same as this bug #2200.
I still don't know why this happens only sometimes and not every time though.
This is from a Windows process dump where this thread is shown to be hung.
Additional context
N/A
The text was updated successfully, but these errors were encountered: