-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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] Race condition in BsonMapper #2536
Comments
There is an issue here: mbdavid/LiteDB#2536, which I believe is causing flaky behavior in the OPC-UA tests.
There is an issue here: mbdavid/LiteDB#2536, which I believe is causing flaky behavior in the OPC-UA tests.
Oh i see it now. Thats pretty bad, i am sorry for that. Would you mind pr'ing a fix? |
This fixes a race condition in BsonMapper, caused by a fix to a different issue in mbdavid#2493. It seems like the current approach of checking the dictionary twice is deliberate. That said, I don't believe reading from a dictionary that may be in the process of being updated is actually safe to begin with.
This fixes a race condition in BsonMapper, caused by a fix to a different issue in mbdavid#2493. It seems like the current approach of checking the dictionary twice is deliberate. That said, I don't believe reading from a dictionary that may be in the process of being updated is actually safe to begin with.
This fixes a race condition in BsonMapper, caused by a fix to a different issue in mbdavid#2493. It seems like the current approach of checking the dictionary twice is deliberate. That said, I don't believe reading from a dictionary that may be in the process of being updated is actually safe to begin with.
I made a PR with a simple fix, though I'm not sure it is the best solution, since it will come with a performance cost that I think the original author of this code wanted to avoid. |
Performance < Stability |
Hey @einarmo can you have a look at my pr and if it solves your issue? My solution doesnt require locking all the time and should still be safe from race conditions |
Version
LiteDB 5.0.21
.NET 8.0.401
Linux (Fedora 38)
Describe the bug
Specifically, what I see is an occasional stacktrace:
when running an expression like
Code to Reproduce
I cannot reproduce this consistently, it only happens once in a while, likely while I am running multiple concurrent transactions not against the same collection, but using the same types.
I believe this is a race condition caused by #2493, here's the possible race I see that this PR introduced:
GetEntityMapper
here, and does not find the mapper.BuildAddEntityMapper
, and goes past this line, adding an entity mapper to the _entities dictionary.GetEntityMapper
.This code has existed for a long time, and this issue only started after updating to the latest version, which contains this fix. There may be a different cause, though my trace above seems plausible.
The text was updated successfully, but these errors were encountered: