flutter_localstorage: Unhandled Exception: FileSystemException: An async operation is currently pending

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 16 (3 by maintainers)

Most upvoted comments

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.

this usually means that you have unawaited call. Make sure you don’t have any unawaited calls to the methods which are async (return futures)

On Tue, Dec 22, 2020, 5:27 PM Shobi notifications@github.com wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lesnitsky/flutter_localstorage/issues/56#issuecomment-749566120, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPYUNVISEIQOLPZBAGK4WDSWCUGPANCNFSM4VFWOZYA .

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.

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!