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

The latest version (6.0.20) seems to be partly broken when used in Xamarin.iOS #424

Closed
raymond-u opened this issue Sep 7, 2018 · 4 comments
Labels

Comments

@raymond-u
Copy link

raymond-u commented Sep 7, 2018

Note: for support questions, please ask on StackOverflow: https://stackoverflow.com/questions/tagged/Akavache . This repository's issues are reserved for feature requests and bug reports.

Do you want to request a feature or report a bug?

bug

What is the current behavior?

I was originally trying to fetch and cache an image using BlobCache.LocalMachine.LoadImageFromUrl(someURL), but I found that it
just stopped responding after I called this method. (Yes, I've set BlobCache.ApplicationName, I even called BlobCache.EnsureInitialized(), and the SQL3 lib wasn't stripped by the linker.) So I did some experiments and tried to find out what was wrong.
After several hours of testing I found that only these methods should work in my circumstances:
1.

BlobCache.LocalMachine.DownloadUrl(someURL).Wait(); // Can fetch the right image file but it won't store it into cache; The cache disappears if I restart the app
var image = BlobCache.LocalMachine.LoadImage(someURL).Wait().ToNative(); // This part is good
BlobCache.LocalMachine.InsertObject<string>(key, value).Wait();
var value = BlobCache.LocalMachine.GetObject<string>(key).Wait(); // This functions well; I can get the correct value right away after a restart

Also, whenever I use await in my code, it falls to infinite deadlock(?). Say, var value = await BlobCache.LocalMachine.GetObject<string>(key);. (Of course I've imported System.Reactive.Linq.) The possible workaround to me is using wait() or subscribe().

BlobCache.LocalMachine.GetOrFetchObject() won't work either.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Try adding these lines of code in a newly created Xamarin.iOS project. Since it's test purpose only so simply add them into AppDelegate.cs file should do.

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            BlobCache.ApplicationName = "Test";
            BlobCache.EnsureInitialized();
            
            // Any Examples from above, say this one
            var image = BlobCache.LocalMachine.LoadImageFromUrl(@"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png").wait().ToNative();
            
            // Initialize the main interface, blahblah
            // But it will just get stuck so the real screen never shows
            Window = new UIWindow();
            Window.RootViewController = new SomeViewController();
            Window.MakeKeyAndVisible();
            return true;
        }

What is the expected behavior?

It at least shouldn't get stuck.

What is the motivation / use case for changing the behavior?

N/A

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.

Akavache 6.0.20
I'm testing with the latest Xamain.iOS & mono build on VS Mac.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

P.S: If I've missed anything, please enlighten me 🤭

@PureWeen
Copy link
Collaborator

@raymond-u what turned out to be the issue?

@raymond-u
Copy link
Author

@PureWeen Sorry I don't know why. 😬 I closed this because I wouldn't be responsible to do any further research on this issue later on 🤭 I turned to use Realm instead, sorry.
Since it seems like I'm the only one who's experiencing this, it might be caused by some outdated libs in my projects? Nuget sometimes gets me outdated dependencies I don't know why. After I installed Realm I found out the Nuget updated one or two of Akavache's dependencies like Reactive-UI. But because at that time I already uninstalled Akavache and swept related codes out from my repository I wasn't being able to find it out whether they were the reason or not. 🤕

@PureWeen
Copy link
Collaborator

Alright :-)

The reason it's locking is because of the Wait. FinishedLaunching is running on the UI Thread so when you call Wait you've now blocked the UI Thread and there are certain initialization that have to happen on the UI Thread but they can't because the UI Thread is blocked with the wait.

In general with Reactive/Tasks you never want to call wait.

I tested LoadImageUrl code with a subscribe and it worked fine.

I also tested it with an async await call

		async void PerformLoad()
		{
			var result = await BlobCache.LocalMachine.LoadImageFromUrl(@"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
		}

And it loaded fine from that as well.

@raymond-u
Copy link
Author

raymond-u commented Sep 10, 2018

@PureWeen Hm but in my case since await wasn't working, that it seemed to block the thread, with some strange error sometimes too ("XXX connection corrupted" things, I don't remember now, but I searched at that time and found it's related to some thread disrupted problems), which is clearly what we don't want. So I turned to use wait() or subscribe()🤔 Anyway. I guess you make some sense that we should use subscribe() or await if possible.

Edit: The error info was 'XPC connection interrupted'.

@lock lock bot added the outdated label Jun 24, 2019
@lock lock bot locked and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants