Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vm_service] IsolateReload event not sent after reloadSources call #49491

Closed
julemand101 opened this issue Jul 20, 2022 · 2 comments
Closed

[vm_service] IsolateReload event not sent after reloadSources call #49491

julemand101 opened this issue Jul 20, 2022 · 2 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on pkg-vm-service triaged Issue has been triaged by sub team

Comments

@julemand101
Copy link
Contributor

julemand101 commented Jul 20, 2022

Tested with:

Dart SDK version: 2.17.6 (stable) (Tue Jul 12 12:54:37 2022 +0200) on "windows_x64"
Dart SDK version: 2.19.0-5.0.dev (dev) (Sat Jul 16 03:26:30 2022 -0700) on "windows_x64"

With:
vm_service: 9.0.0

In an attempt to answer the following Stackoverflow question:
https://stackoverflow.com/questions/73046539/how-can-one-respond-to-a-hot-reload

I got into trying to use the vm_service package to receive events about isolates being reloaded (hot reloaded?). But it does not seem like IsolateReload (or any Isolate event) are being sent when doing reloadSources.

I also checked the web traffic to Dart Observatory and Dart DevTools (both also subscribes to the EventStreams.kIsolate but they seems to also not getting any event for reloading isolates.

But the code (and therefore the Isolate) are being reloaded since I can verify changes to the someMethod() are being loaded every 5 second.

Program for reproduce the issue:

import 'dart:async';
import 'dart:developer';
import 'dart:isolate';

import 'package:vm_service/vm_service.dart' as vm;
import 'package:vm_service/vm_service_io.dart' as vmi;

void main() async {
  final serverWebSocketUriString =
      (await Service.getInfo()).serverWebSocketUri.toString();
  final vmService = await vmi.vmServiceConnectUri(serverWebSocketUriString);

  // Documented to subscribe to:
  //   IsolateStart, IsolateRunnable, IsolateExit,
  //   IsolateUpdate, IsolateReload, ServiceExtensionAdded
  vmService.onIsolateEvent.listen((event) {
    print('onIsolateEvent: ${event}'); // <-- never called
  });

  final status = await vmService.streamListen(vm.EventStreams.kIsolate);
  print(status.json); // {type: Success}

  final isolateId = Service.getIsolateID(Isolate.current)!;
  startHotReloadTimer(vmService, isolateId);
}

Timer startHotReloadTimer(vm.VmService vmService, String isolateId) =>
    Timer.periodic(const Duration(seconds: 5), (_) async {
      final response = await vmService.reloadSources(isolateId, force: true);
      // Same issue when doing:
      // final response = await vmService.reloadSources(isolateId);
      
      print('response: $response'); // response: [ReloadReport success: true]
      someMethod();
    });

void someMethod() {
  print('String I manipulate manually to verify the code have been reloaded');
}

I have tried executing the program with the following different ways without any observed difference:

dart --enable-vm-service program.dart
dart run --enable-vm-service program.dart
dart --observe program.dart
dart run --observe program.dart
@lrhn lrhn added the area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. label Jul 20, 2022
@a-siva
Copy link
Contributor

a-siva commented Jul 20, 2022

//cc @bkonyi

@bkonyi bkonyi self-assigned this Jul 21, 2022
@szotp
Copy link

szotp commented Dec 23, 2022

I can confirm this. Workaround: https://pub.dev/packages/hotreloader

Hot reload is one of the best features of dart, so it's weird to see it so neglected.

For example: I'm writing a script that parses dart code into a syntax tree and then generated some stuff from it.
It takes few seconds to run the script and parse the tree. Hot reload gives me this sweet <1s feedback loop in which I can parse the AST once, and then regenerate output every time I change my script.

This kind of thing should be supported right out of the box imo.

@bkonyi bkonyi assigned derekxu16 and unassigned bkonyi Jan 3, 2023
@a-siva a-siva added triaged Issue has been triaged by sub team P2 A bug or feature request we're likely to work on labels Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on pkg-vm-service triaged Issue has been triaged by sub team
Projects
None yet
Development

No branches or pull requests

6 participants