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

Unhandled Exception: FileSystemException: An async operation is currently pending #56

Closed
nilevars opened this issue Dec 22, 2020 · 16 comments

Comments

@nilevars
Copy link

I updated the localstorage version to ^3.0.6+9 but I get the following exception

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: FileSystemException: An async operation is currently pending, path = '/Users/username/Library/Developer/CoreSimulator/Devices/5C337305-95CC-4BB3-926F-B607E154A1A9/data/Containers/Data/Application/CD793806-AF33-4755-B7E2-D110B346032A/Documents/filename.json'

This is the output of Flutter doctor :

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, v1.17.5, on macOS 11.1 20C69, locale en-KW)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.52.1)
[✓] Connected device (1 available)

• No issues found!

If this exception is not caused by this library, Kindly let me know.

@ppshobi
Copy link

ppshobi commented Dec 22, 2020

We are also facing this issue. Downgraded to 3.0.1+4 to fix it for now

@lesnitsky
Copy link
Owner

lesnitsky commented Dec 22, 2020 via email

@nilevars
Copy link
Author

Thanks @lesnitsky I missed some await statements

@acamenhas
Copy link

I have this problem too. Downgraded to 3.0.1+4 solved my problem.
Thanks @ppshobi

@lesnitsky
Copy link
Owner

@acamenhas downgrading is bad idea :)
Please let me know if this comment is clear enough and solves the problem

@pierrea
Copy link

pierrea commented Jan 23, 2021

This issue is happening to me as well after upgrading to 3.0.6+9.
It is possible there are some unawaited calls in my code (digging into that now) but regardless, this didn't happen before. I'm curious if you made it become less tolerant towards unawaited calls in the latest updates. Thanks!

@felix-ht
Copy link

felix-ht commented Mar 5, 2021

We have the same issue with 3.0.6+9 - with 3.0.3+6 everything is good. What changed between the releases? @lesnitsky

@ltphy
Copy link

ltphy commented Mar 11, 2021

The problem will occur If two operation write at the same time to the file stored in local storage, while the first operation has not finished to write. (The write operation is still locked)
This means you have to check whether is any operation did not use await before the error happened.

@felix-ht
Copy link

felix-ht commented Mar 16, 2021

i don't think that await is enough to guarantee that this does not happen. If you run some code and this code causes a write to local storage and awaits it, the rest of the app keeps running. If there is any other code scheduled to run it will run, and this code can access local storage again - causing this error.

@tmorone-rezi
Copy link

This package works well to provide mutually exclusive access to a resource.
https://pub.dev/packages/mutex

await mutex.protect(() async => await _cache?.setItem(itemKey, item, toEncodable));

@felix-ht
Copy link

@lesnitsky would i be possible to get a solution similar to the one given by @tmorone-rezi in the library, so that this error fundamentally cannot happen any longer?

A very common use case for this library is to store state. State changes on user input, so even with the trivial increment flutter example, where you press the increment button and a value gets incremented, you can get this error. Assuming that you press it fast enough and you use setItem to save the state on any modification.

I checked the exact same code that was causing issues with this code and simply replaced it with sembast and the issues where gone.

@pauline-jubiliz
Copy link

pauline-jubiliz commented Mar 1, 2022

Hello,

@lesnitsky

I have the same problem ! This is my function :

final LocalStorage _localStorageNotification = LocalStorage('Notifications');
Future<void> setItemNotification(final Map<String, String> mapDates) async
{
bool ready = await _localStorageNotification.ready;
if (ready) { await _localStorageNotification.setItem(dates, mapDates); }
}

But even if the storage is ready, I have the error on setItem :
FileSystemException (FileSystemException: An async operation is currently pending, path = '')

My version : 4.0.0+1

Any idea where the problem might come from?

Thank you!

@felix-ht
Copy link

felix-ht commented Mar 1, 2022

quite frankly i would suggest to move to sembast - its a bit more complicated to use - but has no problems such as this. It is also much more future proof if you ever need more advanced features.

@SeaRoth
Copy link

SeaRoth commented Apr 23, 2022

I keep running into this problem and unfortunately will be moving away from LocalStorage

@garyodonoghue
Copy link

If it's any use to anyone, but i was having the same trouble, and thought i had added all the necessary awaits, but i was using a forEach loop which will not wait until each async function is executed before moving on, so that was the problem, changed it to not use forEach and then it waits correctly, and i dont get this exception, see
https://stackoverflow.com/questions/51106934/my-async-call-is-returning-before-list-is-populated-in-foreach-loop

@lesnitsky
Copy link
Owner

#56 (comment)

Repository owner locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests