You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ObjectBox crashes the app if the store is accessed in an Isolate (using the store reference to get access to the store) after the store is closed in the main Isolate, with a EXC_BAD_ACCESS error.
Basic info:
ObjectBox version: 1.3.0
Flutter SDK: 2.10.0
Dart SDK: 2.16.0
Null-safety enabled: yes
Reproducibility: always
OS: macOS Monterey
Device/Emulator: Simulator (but it's also reproducible in a physical device)
Steps to reproduce
Open the store
Spawn an isolate that accesses the store, passing the store.reference and building the store in the Isolate with Store.fromReference.
Close the store in the main isolate
In the spawned isolate, try to write some data to the store after it has been closed in the main isolate - use Future.delayed for that.
Expected behavior
An exception should be thrown, but the app shouldn't crash.
Code
This is reproducible with this minimal app, just click the Run button.
import'dart:isolate';
import'package:exec_bad_access/objectbox.g.dart';
import'package:flutter/material.dart';
import'package:flutter/services.dart';
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({Key? key}) :super(key: key);
@overrideWidgetbuild(BuildContext context) {
returnconstMaterialApp(
home:ObjectBoxTest(),
);
}
}
@Entity()
classUser {
int id =0;
String name ='';
}
classObjectBoxTestextendsStatelessWidget {
constObjectBoxTest({ Key? key }) :super(key: key);
@overrideWidgetbuild(BuildContext context) {
returnColumn(
mainAxisSize:MainAxisSize.max,
mainAxisAlignment:MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
print('open store');
final store =awaitopenStore();
print('spawn isolate');
awaitIsolate.spawn(backgroundTask, store.reference);
print('wait for the isolate to start running before closing the store');
awaitFuture.delayed(constDuration(seconds:2));
print('close the store');
store.close();
},
child:constText('Run')
),
]
);
}
}
voidbackgroundTask(ByteData storeRef) async {
print('rebuild the store from the reference');
Store store =Store.fromReference(getObjectBoxModel(), storeRef);
print('get the box');
final box = store.box<User>();
print('wait 10 seconds - this will run after the store is closed in the main isolate');
awaitFuture.delayed(constDuration(seconds:10));
print('create user');
final user =User();
user.name ='Test';
box.put(user);
}
Maybe some more details: #376 introduces a new attach API to Store that would keep the internal store open until all references are closed. So in above example it would be safe to close the store in one isolate while it still might be used in another.
ObjectBox crashes the app if the store is accessed in an Isolate (using the store reference to get access to the store) after the store is closed in the main Isolate, with a EXC_BAD_ACCESS error.
Basic info:
Steps to reproduce
store.reference
and building the store in the Isolate withStore.fromReference
.Expected behavior
An exception should be thrown, but the app shouldn't crash.
Code
This is reproducible with this minimal app, just click the
Run
button.This is the pubspec.yaml:
Logs, stack traces
This error is visible only by running the app in xcode:
The text was updated successfully, but these errors were encountered: