Skip to content

flutter attach should not assume that the application dill and local filesystem are in sync #38320

Closed

Description

@jonahwilliams

During flutter run, a dill file (1) contain all sources is built and bundled into the APK/IPA that is installed onto the device. Then, when the tool attaches to the observatory for debugging and hot reload, it initializes the frontend server from the existing dill file and recompiles all sources (2). For here on out, any time a hot reload is requested, the filesystem is stat'd and updated sources are passed into the frontend server. This produces an incremental dill based on the updated sources and the state of (2). By construction (1) and (2) are identical files, so this works as expected.

During flutter attach, an APK/IPA that has already been built in some other tool/process/session is started on a device. This must contain a dill file (1) from some previous compile. We connect to the observatory and initialize the frontend server from an existing dill file (if it exists) and recompile all sources into a new dill file (2). For here on out, any time a hot reload is requested, the filesystem is stat'd and updated sources are passed into the frontend server. Unlike flutter run, there is no guarantee that (1) and (2) were the same file.

Consider the following sequence of user actions:

  1. User edits flutter sources and builds APK, installs on device.
  2. User further edits source code.
  3. User starts app and runs flutter attach.
  4. User requests hot reload, changes from (2) are not observed.

By the time the tool has reached (4), it assumes based on the flutter run workflow that the initial compile from the frontend server represents the source of truth. Therefore the hot reload does not result in any changes, since in this case the stat tells us the file was updated prior to the compile.

Fix:
In the case of flutter attach, the first hot reload should assume that every source file has been invalidated. This will significantly slow down the first reload, but will not effect subsequent reloads.

See also: #37976

cc @zanderso @feinstein

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Aug 12, 2019
  2. zanderso commented on Aug 12, 2019

    @zanderso
    Member

    Is it also the case that a sufficiently speedy person (or bot/ide) could modify sources between (1) and (2) during flutter run?

  3. added
    a: existing-appsIntegration with existing apps via the add-to-app flow
    a: qualityA truly polished experience
    on Aug 12, 2019
  4. jonahwilliams commented on Aug 12, 2019

    @jonahwilliams
    ContributorAuthor

    Yes, that's a good point. I'll confirm locally but changes after the APK/IPA has been built but before the attach are likely to be lost in the run case as well.

  5. modified the milestones: December 2019 (Add-to-App), , on Jan 7, 2020
  6. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  7. removed this from the milestone on Aug 17, 2020
  8. added 3 commits that reference this issue on Dec 15, 2022
  9. 9 remaining items

  10. added 6 commits that reference this issue on Dec 16, 2022
  11. added a commit that references this issue on Dec 16, 2022
  12. added a commit that references this issue on Jan 19, 2023
  13. jonahwilliams commented on Jan 25, 2023

    @jonahwilliams
    ContributorAuthor

    I'm closing this issue because I don't think this is possible to fix in a way that is generally useful. Performing a hot restart to bring things in sync is not particularly expensive, but doing it every time adds a lot of overhead

  14. feinstein commented on Jan 26, 2023

    @feinstein
    Contributor

    But wouldn't it be needed only once, after flutter attach has started?

  15. github-actions commented on Mar 4, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: existing-appsIntegration with existing apps via the add-to-app flowa: qualityA truly polished experiencetoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions