webdev icon indicating copy to clipboard operation
webdev copied to clipboard

Hot restart problems on pause

Open annagrin opened this issue 2 years ago • 5 comments

Hot restart is not working properly if the flutter app is paused when the hot restart is initiated.

Repro steps:

  • Open flutter hello_world project in VSCode
  • Add a breakpoint on the line that calls runMain
  • Hot restart

Observe the breakpoint not hitting.

Notes To perform the hot restart we need the app to be running, so we remove all the breakpoints, resume the app, then hot restart, and re-establish breakpoints after the main is reloaded. This seems to be too late for the breakpoints to hit.

Suggestion Break hot restart into two steps - running the bootstrap and running main (flutter engine main in that case). Then re-establishing the breakpoints can be done in between the two.

Some issues we are encountering currently with this suggestion

  • Race condition between the engine initialization and hot restart. The previous isolate's engine initialization sometimes is delayed and executes in the middle of hot restart, so the engine cleanup is not performed correctly.

  • Hello world app is using an old bootstrap strategy: https://github.com/flutter/flutter/blob/57c7aa53c178f722aec19a76a60552e78ad09997/examples/hello_world/web/index.html#L5

  • After replacing it with a new one,

<html>
  <head>
    <head>
        <title>Hello, World</title>
    </head>
    <script src="flutter.js" defer></script>
  </head>
  <body>
    <script>
        window.addEventListener('load', function (ev) {
          // Download main.dart.js
          _flutter.loader.loadEntrypoint({
            onEntrypointLoaded: async function(engineInitializer) {
              // Immediately run the app
              await engineInitializer.autoStart();
            }
          });
        });
      </script>
  </body>
</html>

I am hitting the following: https://github.com/flutter/flutter/issues/121905. Currently blocked on this, will continue the investigation after it is fixed.

annagrin avatar Mar 06 '23 20:03 annagrin

FYI, I just merged https://github.com/flutter/engine/pull/40154 which fixes the hot restart issue you referenced (https://github.com/flutter/flutter/issues/121905).

mdebbar avatar Mar 15 '23 20:03 mdebbar

Any suggestion when it will be available on flutter beta channel ?

For us it is a showstopper at the moment w/o doing roll-back changes from v3.9(beta) back to 3.7.7 (stable)...

RoarGronmo avatar Mar 21 '23 10:03 RoarGronmo

Still an issue with following version

Flutter is already up to date on channel beta
Flutter 3.9.0-0.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 0df8557c56 (5 days ago) • 2023-03-23 22:02:01 -0500
Engine • revision 1cc4b2d280
Tools • Dart 3.0.0 (build 3.0.0-290.3.beta) • DevTools 2.22.2

RoarGronmo avatar Mar 29 '23 10:03 RoarGronmo

@RoarGronmo you can check when this lands by looking at the tags in the roll commit from flutter/engine to flutter/flutter that contains this feature, in this case:

https://github.com/flutter/flutter/commit/7003bfab316a9e1f02221e50b935fa53be63088f

It seems the earliest tag associated with the commit is: 3.9.0-9.0.pre, which seems slightly newer than the beta channel.

(The fix is currently available on master, of course.)

ditman avatar Mar 29 '23 17:03 ditman

@jyameo is going to see if he can reproduce this still.

bkonyi avatar Oct 02 '24 17:10 bkonyi

I was not able to reproduce this issue on Flutter 3.24.3 (Dart 3.5.3, DevTools 2.37.3), so it appears to be resolved.

jyameo avatar Oct 22 '24 19:10 jyameo