-
Notifications
You must be signed in to change notification settings - Fork 369
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
DriftIsolate.connect waits forever occasionally #3182
Comments
Do you have a way to reproduce this reliably if you can hit this in the debugger? In drift version 2.20.0, you can pass a timeout parameter in |
I also tried to find a stable way to reproduce it, but unfortunately I couldn't find it. However, it does not occur when connecting the isolate for the first time from the UI while opening the app, and it occurs when connecting the second time from a background service. Currently, I set a timeout in the |
Yeah that doesn't sound good... To me, it sounds like there might be a fatal error in the background isolate that we're somehow missing... isolateSpawn: <T>(function, arg) async {
final errorPort = ReceivePort();
final exitPort = ReceivePort();
errorPort.listen((error) {
print('Unhandled drift isolate error: $error');
});
exitPort.first.whenComplete(() {
exitPort.close();
errorPort.close();
});
return await Isolate.spawn(
function,
arg,
errorsAreFatal: true,
onError: errorPort.sendPort,
onExit: exitPort.sendPort,
);
}, Do you see any errors being printed before the timeout in that case? |
Hi!
I'm working on app which needs to access database in UI isolate and background service also. When app is opened, on main function, I launch a drift isolate and connect main isolate to it, register Sendport to IsolateNameServer also. After that, user start background service which collects location information into drift database. So when the background service is launched (other isolate), on onStart() callback function, service searches for the sendport on the IsolateNameServer and call connect function. So two client isolates (main and background) are connected to the drift isolate, location data is collected to local db in background service and presented to ui in main isolate through query stream. Below is the core code.
drift_database.dart
main.dart
position_service.dart
This works well but occasionally 'await LocalDatabase.instance();' is never finished and when I look deep into the code, I figured out that 'await isolate.connect();' is never finished because 'await client.serverInfo;' in 'connectToRemoteAndInitialize()' function in the 'remote.dart' file is never return some value.
I guess this happens when this app tries to connect to the drift isolate which has some problem, but I couldn't know how to reproduce this issue. Should I ping with timeout to this drift isolate before every database access? Is there any solution? Sorry for my bad English and thank you!
The text was updated successfully, but these errors were encountered: