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

killAll() sends the main isolate into an unknown state #107

Open
frank06 opened this issue May 25, 2022 · 3 comments
Open

killAll() sends the main isolate into an unknown state #107

frank06 opened this issue May 25, 2022 · 3 comments
Labels
good first issue Good for newcomers

Comments

@frank06
Copy link

frank06 commented May 25, 2022

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await FlutterIsolate.killAll();
  print('done');
  // ...
}

The string "done" never gets printed, execution halted (but not paused) and with no exceptions.

Why do I want to kill all isolates when starting the app? Because my isolate is a long-running one (doesn't kill() itself) and I don't want zombie isolates accumulating every time I hot restart. Flutter has no known callback to execute code just before a hot restart.

Versions:

  • flutter: 2.10.3
  • flutter_isolate: ^2.0.2
@frank06
Copy link
Author

frank06 commented May 25, 2022

Found a workaround:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // ignore: unawaited_futures
  FlutterIsolate.killAll();
  
  Future.delayed(Duration(milliseconds: 100), () async {
    print('done');
    // ...
  });
}

@ghost
Copy link

ghost commented Jun 1, 2022

Same issue, I notice that even with isolate instance, isolate.kill(priority: Isolate.immediate); didn't work when isolate got a while / recursive inside... Kill not working.

@nmfisher
Copy link
Collaborator

nmfisher commented Jun 3, 2022

These both look like the method channel just doesn't report back appopriately, looks easily fixable.

@nmfisher nmfisher added the good first issue Good for newcomers label Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants