π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix Rust ML runtime cleanup ownership
laurenspriemea899844ec64
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dartindex 1649410528..8ee9630856 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart@@ -142,7 +142,8 @@ class MLIndexingIsolate extends SuperIsolate {}Future<void> releaseRustRuntime() async {- if (!_shouldUseRustMl) {+ final cachedRustRuntimeArgs = _cachedRustRuntimeArgs;+ if (cachedRustRuntimeArgs == null) {return;}if (!isIsolateSpawned) {@@ -150,12 +151,16 @@ class MLIndexingIsolate extends SuperIsolate {return;}return _rustRuntimeLock.synchronized(() async {- _cachedRustRuntimeArgs = null;+ if (_cachedRustRuntimeArgs == null) {+ return;+ }if (!isIsolateSpawned) {+ _cachedRustRuntimeArgs = null;return;}try {await runInIsolate(IsolateOperation.releaseRustMlRuntime, {});+ _cachedRustRuntimeArgs = null;} catch (e, s) {_logger.warning("Could not release rust runtime in isolate", e, s);}diff --git a/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart b/mobile/apps/photos/lib/utils/isolate/isolate_operations.dartindex 53e4c81d0b..859a7a4779 100644--- a/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart+++ b/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart@@ -315,10 +315,12 @@ Future<void> _ensureRustLoaded() async {Future<void> _ensureRustDisposed() async {// Intentionally a no-op.//- // Rust ML residency is owned by the feature isolate using it, not by the- // generic cache-clear path. This avoids disposing the bridge before- // MLIndexingIsolate has a chance to release its selective indexing-model- // residency during onDispose().+ // Rust ML residency is owned by the feature isolate that prepared it.+ // The generic cache-clear path runs in multiple rust-using isolates, so+ // letting it call process-global ML teardown would allow unrelated isolates+ // to release indexing sessions they do not own. MLIndexingIsolate tracks+ // whether it prepared the runtime and releases it explicitly during its own+ // cleanup, even if the app mode or flags have changed since preparation.}Future<void> _ensureRustRuntimePrepared(Map<String, dynamic> args) async {