Skip to content

[vm] Should native finalizers run on hot-restart #50016

Open

Description

@dcharkes

We guarantee to run all native finalizers before VM-shutdown completes.
We do not guarantee to run all native finalizers before an isolate shuts down.

Should hot-restart have the VM-shutdown semantics? E.g. all heaps get released and all native finalizers are run before hot-restart completes? Or, should it be thought of as simply shutting down all isolates and starting new ones but not stopping and starting the VM?

cc @mraleph

Activity

  1. added
    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
    vm-gcRelated to the VM's garbage collector
    on Sep 20, 2022
  2. rmacnak-google commented on Sep 20, 2022

    @rmacnak-google
    Contributor

    Isn't the finalizer guarantee scoped to the heap / isolate group instead of the VM? I would expect hot-restart to shut down a whole group and meet this guarentee, but maybe hot-restart hasn't been updated since the introduction of isolate groups and is still operating at the isolate level?

  3. maks commented on Sep 20, 2022

    @maks

    I should add that in the example code I added to in flutter/flutter#75528 while I do have a secondary Isolate, I was trying to use the NativeFinalizer in the main Isolate only and it didn't seem to be working with a hot-restart.

  4. mraleph commented on Sep 22, 2022

    @mraleph
    Member

    @maks if you have a secondary isolate that secondary isolate likely keeps the isolate group alive which prevents finalisers from running. Which would explain why native finalizers don't fire. We are probably leaking secondary isolates on restart?

    This might be yet another argument for creating process tree like primitive for isolates similar to what Erlang has.

  5. maks commented on Sep 23, 2022

    @maks

    @mraleph I thought you had spotted the issue, but I just tried adding a Isolate.exit() along with print("exiting Helper Isolate"); on line before it, to my helper Isolate (as I was only using the Isolate to invoke the potentially long running operation of initialising the audio library) and it doesn't seem to help in that I don't see the printf() I have put into my audio library shutdown function and the whole apps still crashes straight after the audio lib initialisation post hot-restart:

    flutter run -d linux lib/main.dart 
    Launching lib/main.dart on Linux in debug mode...
    Building Linux application...                                           
    Syncing files to device Linux...                                    57ms
    
    Flutter run key commands.
    r Hot reload. 🔥🔥🔥
    R Hot restart.
    h List all available interactive commands.
    d Detach (terminate "flutter run" but leave application running).
    c Clear the screen
    q Quit (terminate the application on the device).
    
    💪 Running with sound null safety 💪
    
    An Observatory debugger and profiler on Linux is available at: http://127.0.0.1:32975/fzHarI7Hwfs=/
    flutter: exiting Helper Isolate
    The Flutter DevTools debugger and profiler on Linux is available at:
    http://127.0.0.1:9101?uri=http://127.0.0.1:32975/fzHarI7Hwfs=/
    
    Performing hot restart...                                               
    Restarted application in 214ms.
    flutter: exiting Helper Isolate
    Lost connection to device.
    

    I'm in the middle of tidying up my plugin code for publication, so I'll post a link to the repo here as soon its done in case that would help.

    Irrespective of the above, having a process tree for Isolates similar to Erlangs would be FANTASTIC! 👍🏻 💯 🙏🏻

  6. a-siva commented on Dec 15, 2023

    @a-siva
    Contributor

    I'm in the middle of tidying up my plugin code for publication, so I'll post a link to the repo here as soon its done in case that would help.

    @maks Can you post a link to the repo that you describe above.

  7. maks commented on Dec 16, 2023

    @maks

    @a-siva sorry its been a while since I commented on this issue, I think the project I was working on was this one, but I haven't touched it in quite a while to be honest as I got a bit discouraged trying to get low latency audio working with Dart.

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

    P2A bug or feature request we're likely to work onarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.customer-fluttervm-gcRelated to the VM's garbage collector

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions