Skip to content

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

Description

@julemand101

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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.pkg-vm-servicetriagedIssue has been triaged by sub team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions