Skip to content

Commit

Permalink
fix(supabase_flutter): Add timeout to Hive.openBox to fix hanging iss…
Browse files Browse the repository at this point in the history
…ue (#799)

* fix: Add timeout to Hive.openBox to fix hanging issue

* Update packages/supabase_flutter/lib/src/local_storage.dart
  • Loading branch information
dshukertjr authored Jan 18, 2024
1 parent 059ab77 commit 7fc3ed0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/supabase_flutter/lib/src/local_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class HiveLocalStorage extends LocalStorage {
encryptionCipher = HiveAesCipher(base64Url.decode(encryptionKey!));
}
await Hive.initFlutter('auth');
await Hive.openBox(_hiveBoxName, encryptionCipher: encryptionCipher);
await Hive.openBox(_hiveBoxName, encryptionCipher: encryptionCipher)
.timeout(const Duration(seconds: 1));
}

@override
Expand Down Expand Up @@ -185,7 +186,12 @@ class MigrationLocalStorage extends LocalStorage {
await Hive.initFlutter('auth');
hiveLocalStorage = const HiveLocalStorage();
await sharedPreferencesLocalStorage.initialize();
await migrate();
try {
await migrate();
} on TimeoutException {
// Ignore TimeoutException thrown by Hive methods
// https://github.com/supabase/supabase-flutter/issues/794
}
}

@visibleForTesting
Expand Down

0 comments on commit 7fc3ed0

Please sign in to comment.