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

fix: fix Resource temporarily unavailable for Hive lock file. #387

Merged
merged 1 commit into from Jun 15, 2023

Conversation

andycall
Copy link
Member

@andycall andycall commented Jun 12, 2023

Hive only supports accessing a resource from one instance, and it creates a lock file to avoid conflicts.

If two Dart isolates load the same URL of WebF pages, they will point to the same Hive lock file and report the following error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: lock failed, path = '/Users/andycall.dong/Library/Caches/WebF/LocalStorage/_webf_11988048.lock' (OS Error: Resource temporarily unavailable, errno = 35)
#0      _RandomAccessFile.lock.<anonymous closure> (dart:io/file_impl.dart:1002:9)
<asynchronous suspension>
#1      StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:81:5)
<asynchronous suspension>
#2      HiveImpl._openBox (package:hive/src/hive_impl.dart:111:9)
<asynchronous suspension>
#3      HiveImpl.openBox (package:hive/src/hive_impl.dart:142:12)
<asynchronous suspension>

This patch will attempt to initialize the Hive box twice. When the first load encounters the above error, the second try will remove the lock file and successfully initialize the box.

@andycall andycall added this pull request to the merge queue Jun 15, 2023
Merged via the queue into main with commit 9884634 Jun 15, 2023
37 of 38 checks passed
@andycall andycall deleted the fix/hive_lock_error branch June 15, 2023 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants