diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart
index a27bf928..2e16154b 100644
--- a/lib/encryption/ssss.dart
+++ b/lib/encryption/ssss.dart
@@ -213,11 +213,13 @@ class SSSS {
content.passphrase.iterations = PBKDF2_DEFAULT_ITERATIONS;
content.passphrase.bits = SSSS_KEY_LENGTH * 8;
privateKey = await runInBackground(
- _keyFromPassphrase,
- _KeyFromPassphraseArgs(
- passphrase: passphrase,
- info: content.passphrase,
- ));
+ _keyFromPassphrase,
+ _KeyFromPassphraseArgs(
+ passphrase: passphrase,
+ info: content.passphrase,
+ ),
+ timeout: Duration(seconds: 10),
+ );
} else {
// we need to just generate a new key from scratch
privateKey = Uint8List.fromList(SecureRandom(SSSS_KEY_LENGTH).bytes);
@@ -648,11 +650,13 @@ class OpenSSSS {
'Tried to unlock with passphrase while key does not have a passphrase');
}
privateKey = await runInBackground(
- _keyFromPassphrase,
- _KeyFromPassphraseArgs(
- passphrase: passphrase,
- info: keyData.passphrase,
- ));
+ _keyFromPassphrase,
+ _KeyFromPassphraseArgs(
+ passphrase: passphrase,
+ info: keyData.passphrase,
+ ),
+ timeout: Duration(seconds: 10),
+ );
} else if (recoveryKey != null) {
privateKey = SSSS.decodeRecoveryKey(recoveryKey);
} else {
diff --git a/lib/src/utils/run_in_background.dart b/lib/src/utils/run_in_background.dart
index 728a805f..a985312f 100644
--- a/lib/src/utils/run_in_background.dart
+++ b/lib/src/utils/run_in_background.dart
@@ -16,11 +16,16 @@
* along with this program. If not, see .
*/
+import 'package:famedlysdk/famedlysdk.dart';
import 'package:isolate/isolate.dart';
import 'dart:async';
Future runInBackground(
- FutureOr Function(U arg) function, U arg) async {
+ FutureOr Function(U arg) function,
+ U arg, {
+ Duration timeout,
+ dynamic Function() onTimeout,
+}) async {
IsolateRunner isolate;
try {
isolate = await IsolateRunner.spawn();
@@ -28,9 +33,17 @@ Future runInBackground(
// web does not support isolates (yet), so we fall back to calling the method directly
return await function(arg);
}
+ final sub = isolate.errors
+ .listen((error) => Logs().e('Error caught in isolate', error));
try {
- return await isolate.run(function, arg);
+ return await isolate.run(
+ function,
+ arg,
+ timeout: timeout,
+ onTimeout: onTimeout,
+ );
} finally {
+ await sub.cancel();
await isolate.close();
}
}