Skip to content
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

File sync run in the main isolate for a certain amount of time should report as a performance issue #1727

Open
buenaflor opened this issue Nov 14, 2023 · 7 comments

Comments

@buenaflor
Copy link
Contributor

Description

SImilar to how the native SDKs do it.

Needs investigation first if we can check if it's run in a background isolate

@denrase
Copy link
Collaborator

denrase commented Dec 4, 2023

Found ServicesBinding.rootIsolateToken, which should be able to tell us if we are in the root, or in a background isolate.

A token that represents the root isolate, used for coordinating with background isolates.

This property is primarily intended for use with BackgroundIsolateBinaryMessenger.ensureInitialized, which takes a RootIsolateToken as its argument. The value null is returned when executed from background isolates.

https://api.flutter.dev/flutter/services/ServicesBinding/rootIsolateToken.html

@ueman
Copy link
Collaborator

ueman commented Dec 4, 2023

I think you can also check for the isolate name being 'main'. That way you don't need a dependency on Flutter.

The token is also a recent addition, which is not compatible with the lowest supported Flutter version

@denrase
Copy link
Collaborator

denrase commented Dec 5, 2023

@ueman Do you mean with Isolate.current.debugName? Don't see it documented anywhere beeing set to main for the main isolate. Also it's not guaranteed to be unique.

This name does not uniquely identify an isolate. Multiple isolates in the same process may have the same debugName.

https://api.dart.dev/stable/3.2.2/dart-isolate/Isolate/debugName.html

@ueman
Copy link
Collaborator

ueman commented Dec 5, 2023

I think the debugName falls back to method name it was launched with, not 100% sure though. So there's a good chance the main check actually works. But yeah, it's not guaranteed to always work.

@denrase
Copy link
Collaborator

denrase commented Dec 5, 2023

@buenaflor Checked the cocoa SDK and could not find it at first glance. Can you point me to the right code snippet?

@buenaflor
Copy link
Contributor Author

buenaflor commented Dec 19, 2023

We will need to attach the relevant data:

  • async we already do afaik
  • thread: main or isolate: main something like that, depending on how the backend handles it currently for the native sdks - gotta check how relevant the current detector is for us: see here

Edit: this is blocked by min version Flutter 3.7.0, see here for more info

@denrase
Copy link
Collaborator

denrase commented Jan 30, 2024

Important to know, Flutter Sentry can't be initialised from a background Isolate, as it has some references to APIs that are only available when on main.

Users need to init Dart Sentry separately in the background Isolate in order to use the File integration, as they otherwise do not have access to a valid Hub instance, as isolates don't share any state beyond data passed as arguments and return types.

This behaviour is reflected by the added integration tests in the example test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Blocked
Development

No branches or pull requests

3 participants