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

[BUG] Getting SIGSEGV while reading data from Litedb collection simultaneously in multiple threads #1627

Open
sanjiv-saini opened this issue Apr 13, 2020 · 2 comments
Labels

Comments

@sanjiv-saini
Copy link

Version
LiteDB version: 4.1.4
OS: Android API 27

Describe the bug
I am using Litedb v4 in Xamarin, I am creating liteDatabase connection and getting collections inside it once, and passing the collection to multiple threads which perform givenCollection.findALL().ToList() simultaneously. The app crashes sometimes(not always) resulting in SIGSEGV error, I am not getting what is causing this error.

Code to Reproduce

protected async virtual Task<IEnumerable<T>> ReadAllItems<T>(LiteCollection<T> collection)
{
    return await Task.Run(() =>
    {
          return collection.FindAll().ToList();
     });
}

get the collection objection once and pass to the above method. calling above method multiple times causing the error.

Stacktrace

  at <unknown> <0xffffffff>
	  at System.String:FastAllocateString <0x00037>
	  at System.String:CreateStringFromEncoding <0x00
0fb>
	  at System.Text.UTF8Encoding:GetString <0x002a3>
	  at LiteDB.BsonReader:ReadString <0x00143>
	  at LiteDB.BsonReader:ReadElement <0x00227>
	  at LiteDB.BsonReader:ReadDocument <0x0015b>
	  at LiteDB.BsonReader:ReadElement <0x002af>
	  at LiteDB.BsonReader:ReadDocument <0x0015b>
	  at LiteDB.BsonReader:ReadElement <0x002af>
	  at LiteDB.BsonReader:ReadArray <0x0015b>
	  at LiteDB.BsonReader:ReadElement <0x0031f>
	  at LiteDB.BsonReader:ReadDocument <0x0015b>
	  at LiteDB.BsonReader:ReadElement <0x002af>
	  at LiteDB.BsonReader:ReadDocument <0x0015b>
	  at LiteDB.BsonReader:Deserialize <0x0009b>
	  at LiteDB.QueryCursor:Fetch <0x003eb>
	  at <Find>d__9:MoveNext <0x007a3>
	  at <Find>d__13:MoveNext <0x00e63>
	  at <Find>d__17:MoveNext <0x00593>
	  at System.Collections.Generic.List`1:AddEnumerable <0x00287>
	  at System.Collections.Generic.List`1:.ctor <0x0038f>
	  at <>c__DisplayClass7_0`1:<ReadAllItems>b__0 <0x0013b>
	  at System.Threading.Tasks.Task`1:InnerInvoke <0x000d7>
	  at System.Threading.Tasks04-11 02:13:11.211 F/libc    (13977): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x1b in tid 14021 (Thread Pool Wor)
@lbnascimento
Copy link
Contributor

@sanju-singh Both LiteCollection and LiteDatabase are thread-safe in v4 and can be shared between multiple threads. Your problem seems to be a Mono-specific issue - I don't believe it is even possible to get a segmentation fault in managed code.

@OneCyrus
Copy link

OneCyrus commented Jun 2, 2020

litedb v4 is not thread safe. i made a PR to fix this issue but it's not merged yet. @lbnascimento any chance to get this released?

#1609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants