-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Sentry.close
must be called in an isolate otherwise it won't shut down
#2625
Comments
I tested with the following code. import 'dart:isolate';
import 'package:sentry/sentry.dart';
Future<void> main(List<String> arguments) async {
print('before sentry isolate');
await Isolate.run(_sentryIsolate);
print('after sentry isolate');
}
Future<void> _sentryIsolate() async {
print('sentry isolate start');
await Sentry.init((options) {
options.dsn = 'https://[email protected]/5428562';
});
// await Sentry.close();
print('sentry isolate end');
} It makes no difference if we close sentry or not, the output is the same in both cases. denis@MacBook-Pro metrics % ./perf_test_console_sentry.bin
before sentry isolate
sentry isolate start
sentry isolate end
after sentry isolate @buenaflor Can we reach the user somehow to get a sample where this is occurring? |
cc @bsutton |
here is a link to the source file that had the problem. |
@bsutton Could reproduce with this minimal code: import 'dart:async';
import 'dart:isolate';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> sentryInIsolate() async {
final receivePort = ReceivePort();
final errorPort = ReceivePort();
final exitPort = ReceivePort();
await Isolate.spawn<SendPort>(
_runSentry,
receivePort.sendPort,
onError: errorPort.sendPort,
onExit: exitPort.sendPort,
);
final completer = Completer<void>();
receivePort.listen((message) {
print("receivePort $message");
});
errorPort.listen((error) {
print("onError");
if (!completer.isCompleted) {
completer.completeError(error as Object);
}
});
exitPort.listen((message) {
print("onExit");
if (!completer.isCompleted) {
completer.complete();
}
});
await completer.future;
receivePort.close();
errorPort.close();
exitPort.close();
}
Future<void> _runSentry(SendPort sendPort) async {
sendPort.send("before sentry init");
await Sentry.init((options) {
options
..dsn =
'https://17bb41df4a5343530bfcb92553f4c5a7@o4507706035994624.ingest.us.sentry.io/4507706038157312'
..tracesSampleRate = 1.0;
});
sendPort.send("after sentry init");
sendPort.send("before sentry close");
await Sentry.close(); // If not done, the isolate will not close.
sendPort.send("after sentry close");
} Since sentry is holding onto resources (http, connections, etc.) the correct usage in isolates is to close it at the end. We will update this in our documentation. |
Found out that this works if we do not add the |
|
I added a test and we indeed need to close sentry to make the isolate complete. We should document this behaviour. |
Description
"I'm calling
Sentry.init
in my isolate (the non-flutter variant) and found my isolate wouldn't shutdown until I addedSentry.close
as the last line in the isolate."Let's verify this first and then document it
The text was updated successfully, but these errors were encountered: