-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
Deadlock when multiple key lookups are coalessed and one of them throws an KeyNotFoundException #432
Comments
Note that I get this behavior in Xamarin iOS and Android. I do not get this behavior when I try to wrap this in a unit test on windows. :/ |
@jorisvergeer sorry for the super late reply but do you by chance have a block of code I could see to recreate the issue? I've tried using your description but maybe I'm missing a nuance of how to recreate? await _BlobCache.InvalidateAll()
.SelectMany(_ => Observable.Range(0, 100))
.Select(value =>
{
if (value % 3 == 0)
{
return _BlobCache.InsertObject<SomeObject>(value.ToString(), new SomeObject());
}
return Observable.Return(Unit.Default);
})
.Merge();
await Observable.Defer(() => Observable.Range(0, 100))
.Select(value => _BlobCache.GetObject<SomeObject>(value.ToString()))
.Merge()
.Catch((KeyNotFoundException ke) => Observable.Return<SomeObject>(null));
foreach(var item in Enumerable.Range(0,100))
{
_BlobCache.GetObject<SomeObject>(item.ToString())
.Catch((KeyNotFoundException ke) => Observable.Return<SomeObject>(null))
.Subscribe();
} |
Damn, that is some Rx black magic. But a'm sorry, i do not have an stand alone example. It appeared in our production app, and I tested it in there. |
Fixed by #433 |
Do you want to request a feature or report a bug?
BUG (a nasty one)
What is the current behavior?
When you do multiple select operations in a short amount op time, akavache will optimize this and will coalesce this in a single sqlite lookup.
When in the handling of this result, one of the keys is not found, then any results after this result will not be handled. (Due to a KeyNotFoundException coming out of
elementMap[v].OnCompleted();
)When for example you await on the result on one of those not handled keys, then your code is in a deadlock state.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
Use akavache and do multiple lookups simultaniously so that the optimizer will combine them. Make sure that some of the keys so not exists.
For a complete deadlock example, await the lookups.
What is the expected behavior?
All observables and awaited lookups give either a result or throw KeyNotFoundException.
What is the motivation / use case for changing the behavior?
I don't want my code to deadlock when other pieces of code request values for non-existing keys.
Which versions of Akavache, and which platform / OS are affected by this issue? Did this work in previous versions of Akavache? Please also test with the latest stable and snapshot (https://www.myget.org/feed/Akavache/package/nuget/Akavache) versions.
Latest stable 6.0.27
Other information (e.g. stacktraces, related issues, suggestions how to fix)
Try catch in
GroupUnrelatedSelects
or make sure thatelementMap[v].OnCompleted();
there does not throw the exception.The text was updated successfully, but these errors were encountered: