Repository navigation
Open
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: qualityA truly polished experienceA truly polished experiencefound in release: 2.2Found to occur in 2.2Found to occur in 2.2has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work ont: hot reloadReloading code during "flutter run"Reloading code during "flutter run"team-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.Issues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Description
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
void loop() {
while (true) {
/* Do nothing */
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Center(
child: GestureDetector(
onTap: loop,
child: Container(
child: Text('Hello World'),
),
),
),
),
);
}
}Flutter version: 2.2.3 from stable channel
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: qualityA truly polished experienceA truly polished experiencefound in release: 2.2Found to occur in 2.2Found to occur in 2.2has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work ont: hot reloadReloading code during "flutter run"Reloading code during "flutter run"team-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.Issues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Activity
jonahwilliams commentedon Jul 7, 2021
Both hot reload and hot restart require running code on the UI thread, which cannot be done if it is parked due to an infinite loop or paused via the VM Service. Leaving this open because it would be nice to find a way to detect or deal with this, but In the short term I don't have any ideas.
[-]Hot restart/reload does not work when while loop without await is activated[/-][+]Hot restart/reload does not work if program is stuck in infinite loop[/+]krll-kov commentedon Jul 7, 2021
Well, if i make the function async, the app won't restart either
jonahwilliams commentedon Jul 7, 2021
that is still an infinite loop, I'm not sure why that would change anything
Hixie commentedon Jul 22, 2021
Why does hot restart require running code on the UI thread?
jonahwilliams commentedon Jul 22, 2021
@Hixie IIRC it has to do with Isolate shutdown requirements, but @zanderso would know more.
jonahwilliams commentedon Jul 22, 2021
(this means we also need to disable breakpoints before hot restarts too)
Hixie commentedon Jul 22, 2021
Seems like an implementation detail, not a design requirement. If I want to hot restart my application, I really don't care what it's doing, I just want to terminate it, reset everything, and start over. If it can be done cleanly then great, if it can't then whatever. After all, if the tool isn't going to be able to do it for me, I'm just going to ^C the process and restart it cold!
zanderso commentedon Jul 22, 2021
I'm guessing that hot restart could be made to work without too much difficulty in this case, but at the moment I'd be surprised if the hot restart request had high enough priority to be handled with Dart frames on the stack by the stack overflow check that's implicitly in the loop[1]. Forcibly unwinding the Dart frames and then tearing-down and rebuilding the Isolate doesn't seem like it should be all that much different than what happens with an unhandled exception.
My understanding is that supporting hot reload in this case would be a lot more difficult since you'd have to rebuild the Dart frames in the new world, but my knowledge in this area could be out of date.
@rmacnak-google will know the real answer
[1] Hopefully the stack overflow check in the infinite loop hasn't been optimized away.
rmacnak-google commentedon Jul 22, 2021
Hot reload proper will work just fine even if the Dart code is sitting in an infinite loop (things need to be blocked in foreign code for the VM to be unable to handle service requests). The program will be updated and the infinite loop will continue. Though anything after hot reload proper that wants to run at the next event loop boundary, such as asking the framework to reassemble, would still need to force an unwind to get new events handled. I would highly discourage tooling from automatically doing so because it breaks fix-and-continue debugging (such as reloading when paused at an exception or breakpoint), where the existing stack is valuable context.
For the hot restart case,
Isolate.kill(immediate)would work on such an infinite loop.darshankawar commentedon Jul 28, 2021
Tapping on text and then trying to hot reload / restart shows below:
flutter doctor -v
matanlurey commentedon Jul 10, 2025
@bkonyi 👁️
bkonyi commentedon Jul 11, 2025
Confirmed this still happens.
I think I've managed to fix the hot restart case by just killing all the isolates before performing the restart (see #171988) but I need to run all the tests to verify that hasn't broken something else.
The hot reload case gets stuck invoking the
ext.flutter.reassembleservice extension, which makes sense since service extensions only execute once the event loop has a chance to process the next event. If the infinite loop contains an asynchronous gap, we don't get stuck. Having an infinite loop like this would already cause the UI isolate to become unresponsive, so I'm not too concerned about hot reload not working here as long as hot restart can act as an escape hatch.flutter-triage-bot commentedon Nov 14, 2025
This issue is assigned to @bkonyi but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
flutter-triage-bot commentedon Jan 31, 2026
This issue was assigned to @bkonyi but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.