flutter_isolate icon indicating copy to clipboard operation
flutter_isolate copied to clipboard

`killAll()` sends the main isolate into an unknown state

Open frank06 opened this issue 2 years ago • 3 comments

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 avatar May 25 '22 19:05 frank06

Found a workaround:

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

frank06 avatar May 25 '22 19:05 frank06

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.

ghost avatar Jun 01 '22 11:06 ghost

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

nmfisher avatar Jun 03 '22 09:06 nmfisher