dart_interactive icon indicating copy to clipboard operation
dart_interactive copied to clipboard

interactive command does not work as shown

Open oezg opened this issue 1 year ago • 22 comments

Describe the bug I used the installation guide but the interactive more did not work.

To Reproduce after the installation and adding to the PATH I ran interactive but the repl did not start as shown in the website. Instead I get this message: Run: dart [--enable-vm-service=43935, file:///home/..../.pub-cache/global_packages/interactive/bin/interactive.dart-3.4.3.snapshot, --vm-service-was-enabled] Workspace: /tmp/dart_interactive_workspace_2024-06-12T010133935832 The Dart VM service is listening on http://127.0.0.1:43935/fdZBpSYCk6k=/ The Dart DevTools debugger and profiler is available at: http://127.0.0.1:43935/fdZBpSYCk6k=/devtools?uri=ws://127.0.0.1:43935/fdZBpSYCk6k=/ws

Expected behavior the terminal will show the repl with >>> and respond to my prompts

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Linux Fedora

Additional context when I go to the link, connected app type is Dart CLI, VM Service Connection: ws://127.0.0.1:43935/fdZBpSYCk6k=/ws

oezg avatar Jun 11 '24 23:06 oezg

Hi! Thanks for opening your first issue here! :smile:

welcome[bot] avatar Jun 11 '24 23:06 welcome[bot]

Hmm, I cannot reproduce locally:

interactive
Building package executable... (3.2s)
Built interactive:interactive.
Run: /Users/tom/fvm/versions/3.22.0/bin/cache/dart-sdk/bin/dart [--enable-vm-service=61753, file:///Users/tom/.pub-cache/global_packages/interactive/bin/interactive.dart-3.4.0.snapshot, --vm-service-was-enabled]
The Dart VM service is listening on http://127.0.0.1:61753/nLZukNycYk4=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:61753/nLZukNycYk4=/devtools?uri=ws://127.0.0.1:61753/nLZukNycYk4=/ws
Workspace: /var/folders/j5/j6ymn7yd70564hzt31pq_0g80000gn/T/dart_interactive_workspace_2024-06-12T073635644668
>>> print(42)
42
[InstanceRef id: objects/null, kind: Null, identityHashCode: -1, classRef: [ClassRef id: classes/170, name: Null, library: [LibraryRef id: libraries/@0150898, name: dart.core, uri: dart:core]]]

But your description looks similar to https://github.com/fzyzcjy/dart_interactive/issues/92.

Since I do not have a reproducible environment, could you please check whether it stucks (or provide a reproducible env)? For example, one way is to run a debugger on it, another way is to add a lot of print and see. The package (https://github.com/fzyzcjy/dart_interactive/tree/master/packages/interactive) is nothing but a standard Dart command line program, so it would be easy to clone and run locally for debugging/modifying.

fzyzcjy avatar Jun 11 '24 23:06 fzyzcjy

I removed the dart-sdk from /opt/, downloaded, extracted and copied dart sdk 3.4.4 to /opt/. I used dart pub global deactivate interactive and then dart pub global activate interactive to refresh the installation.

$ which interactive
~/.pub-cache/bin/interactive

However the problem persists and I cannot see the interactive prompt >>>, instead this is the output:

$ interactive
Run: dart [--enable-vm-service=44349, file:///home/oezg/.pub-cache/global_packages/interactive/bin/interactive.dart-3.4.4.snapshot, --vm-service-was-enabled]
Workspace: /tmp/dart_interactive_workspace_2024-06-12T234104656045
The Dart VM service is listening on http://127.0.0.1:44349/fU8SNuHSDK4=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:44349/fU8SNuHSDK4=/devtools?uri=ws://127.0.0.1:44349/fU8SNuHSDK4=/ws

oezg avatar Jun 12 '24 21:06 oezg

I am just a beginner with dart. I cloned the repo, and hit dart run inside the interactive package. The result is the same:

interactive]$ dart run
Building package executable... 
Built interactive:interactive.
Run: dart [--enable-vm-service=38049, file:///home/oezg/tries/dart/dart_interactive/packages/interactive/.dart_tool/pub/bin/interactive/interactive.dart-3.4.4.snapshot, --vm-service-was-enabled]
Workspace: /tmp/dart_interactive_workspace_2024-06-12T235213133939
The Dart VM service is listening on http://127.0.0.1:38049/xmPtEZa3kZk=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:38049/xmPtEZa3kZk=/devtools?uri=ws://127.0.0.1:38049/xmPtEZa3kZk=/ws

oezg avatar Jun 12 '24 21:06 oezg

I didn't install Flutter, I only installed dart from the zip archive. Can this be the problem? My default browser is Brave. Can this be a problem? I don't have Chrome installed on my computer. Can this be a problem?

oezg avatar Jun 12 '24 21:06 oezg

Hi, as is suggested above, could you please try to add a bunch of print and see where it gets stuck? For example:

  • Clone this repo, say it is at /path/to/dart_interactive
  • Add print('aaaa'); above this line https://github.com/fzyzcjy/dart_interactive/blob/5e4308fa2835e99262e82d044d76bd566b78a918/packages/interactive/lib/src/main.dart#L55. (And similarly, add a ton of various prints to a lot of lines).
  • At folder /path/to/dart_interactive/packages/interactive, run dart run interactive
  • Look at outputs. Suppose aaaa is printed, then we know it is executed; otherwise it is not. We can bisect to see what exact line fails.

fzyzcjy avatar Jun 12 '24 23:06 fzyzcjy

@oezg Looks like OS-related bug for me. Cannot reproduce on Windows and MacOS. Try to debug interactive command and find the bug. Then we'll submit a patch to the interactive repo.

AlexeyBukin avatar Jun 13 '24 01:06 AlexeyBukin

Not working on mac os to. Probably not supported with Dart 3.4.3 or Dart 3 at all

rkyrychuk avatar Jun 27 '24 22:06 rkyrychuk

@fzyzcjy I tried to dig deeper and discovered that VmService stops responding after creating an Isolate with the generated code. In WorkspaceIsolate.create, the vm service is successfully used before creating the Isolate, but after that, the method vmService.getVM never completes. This method is used to get the isolate id, so I tried replacing it with Service.getIsolateID(isolate), which worked, and I entered the REPL, seeing the coveted >>>. However, when entering code, during the ReloadSources phase, the method vmService.reloadSources is called, which again never completes.

I also found out that when running with dart run, everything works. But if you build the kernel, as the pub global activate command does, this error occurs.

Dart SDK version: 3.4.3 (stable) (Tue Jun 4 19:51:39 2024 +0000) on "macos_arm64"

Maksimka101 avatar Jul 16 '24 21:07 Maksimka101

@Maksimka101 Hmm... Do you mean it is stuck at calling Dart's vm service? (or it is stuck at dart_interactive code), if the former maybe we can create an issue on Dart repo asking about this.

fzyzcjy avatar Jul 17 '24 00:07 fzyzcjy

I'm talking about dart's vm service

Maksimka101 avatar Jul 17 '24 06:07 Maksimka101

@fzyzcjy Can you please tell what is your machine, os, dart version and how do you launch the app (with or without compiling it)?

Maksimka101 avatar Jul 17 '24 06:07 Maksimka101

@Maksimka101 I personally use macos, and you can check https://github.com/fzyzcjy/dart_interactive/blob/master/.github/workflows/ci.yaml for various machines and versions etc

fzyzcjy avatar Jul 17 '24 09:07 fzyzcjy

For me, there is a race condition. Execution gets stuck here normally:

https://github.com/fzyzcjy/dart_interactive/blob/1e9e1ae28e3c7a1542a45f441150611f856c6739/packages/interactive/lib/src/workspace_isolate.dart#L43

But putting a sleep at the beginning of main function gets it to work.

https://github.com/fzyzcjy/dart_interactive/blob/1e9e1ae28e3c7a1542a45f441150611f856c6739/packages/interactive/lib/src/main.dart#L53

Tested by running dart run in git HEAD. Dart version:

Dart SDK version: 3.6.0-216.0.dev (dev) (Wed Sep 4 13:34:13 2024 -0700) on "linux_x64"

natrys avatar Sep 05 '24 18:09 natrys

@natrys curious why would getIsolateIds would introduce a race condition... But if this is stuck, maybe we can do a workaround: We can change await vm.getIsolateIds() to a timeout-and-retry. In other words, we timeout on e.g. 1s and if it timeouts we retry again and again.

fzyzcjy avatar Sep 06 '24 05:09 fzyzcjy

@fzyzcjy Had time to do a little more testing. I feel like the issue might be in the relationship between these two lines:

https://github.com/fzyzcjy/dart_interactive/blob/1e9e1ae28e3c7a1542a45f441150611f856c6739/packages/interactive/lib/src/executor.dart#L33-L35

As is, it gets stuck when executing the second line. If I put await Future<void>.delayed(const Duration(seconds: 1)); before both lines, then it works fine. If I put this in-between them, then it just crashes/exits (not even gets stuck).

Tried adding retry logic like:

    VmServiceWrapper vm;
    WorkspaceIsolate workspaceIsolate;
    while (true) {
      try {
        vm = await VmServiceWrapper.create();
        workspaceIsolate = await WorkspaceIsolate.create(vm, workspaceFileTree)
            .timeout(const Duration(seconds: 1));
        break;
      } on TimeoutException {
        print('Trying again...');
        await Future<void>.delayed(const Duration(seconds: 1));
      }
    }

It works in the second try as I would expect. However something is still not quite right because when I do C-d on the repl, then it gets stuck instead of exiting cleanly.

natrys avatar Sep 06 '24 12:09 natrys

Hmm... Again that's quite weird... Maybe the next step can be reducing the same to bare minimum, i.e. only call Dart vm apis. Then, if the problem still exists, that may be a bug related to Dart lang, and we can create a bug report there.

fzyzcjy avatar Sep 06 '24 13:09 fzyzcjy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 07 '24 03:11 stale[bot]

I have the same issue on linux. Just installed and when I run interactive I get the same output with no interactive prompt.

dart --version
Dart SDK version: 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "linux_x64"

CBBosman avatar Nov 12 '24 08:11 CBBosman

Just tested with Dart 3.7.0 beta on Windows 11, and I don't have the >>> output.

BeezBeez avatar Dec 19 '24 18:12 BeezBeez

Can confirm the issue on macOS 14.7.2 dart --version Dart SDK version: 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "macos_arm64"

I have Dart installed through Flutter. But it seems to work when I clone the repo and use dart run

Edit: Deactivating and activating seemed to work

jdk-21 avatar Jan 13 '25 12:01 jdk-21

I guess this bugs existence is quite well established alredy, but in any case can report that this issue happens on freshly installed interactive on Fedora 41 and:

dart --version
Dart SDK version: 3.7.0 (stable) (Wed Feb 5 04:53:58 2025 -0800) on "linux_x64"

timolehto avatar Mar 05 '25 10:03 timolehto

this problem is in my computer , dart version is 3.4.3, in windows wsl. output is

Run: /home/u/.x-cmd.root/local/data/asdf/installs/dart/3.4.3/bin/dart [--enable-vm-service=42045, file:///home/soluty/.pub-cache/global_packages/i nteractive/bin/interactive.dart-3.4.3.snapshot, --vm-service-was-enabled] Workspace: /tmp/dart_interactive_workspace_2025-03-13T133053492751 The Dart VM service is listening on http://127.0.0.1:42045/i2X3vLIH2B4=/ The Dart DevTools debugger and profiler is available at: http://127.0.0.1:42045/i2X3vLIH2B4=/devtools?uri=ws://127.0.0.1:42045/i2X3vLIH2B4=/ws

soluty avatar Mar 13 '25 05:03 soluty

I was running into this on macOS 15.3.1 (M2) with dart 3.6.0 using the VS Code terminal

$ dart pub global activate interactive
Downloading packages... . 
+ _fe_analyzer_shared 82.0.0
+ analyzer 7.4.1
+ args 2.7.0
+ async 2.13.0
+ cli_repl 0.2.3
+ collection 1.19.1
+ convert 3.1.2
+ crypto 3.0.6
+ file 7.0.1
+ glob 2.1.3
+ interactive 1.4.1
+ js 0.6.7 (0.7.2 available)
+ logging 1.3.0
+ meta 1.16.0
+ package_config 2.2.0
+ path 1.9.1
+ pub_semver 2.2.0
+ source_span 1.10.1
+ string_scanner 1.4.1
+ term_glyph 1.2.2
+ typed_data 1.4.0
+ vm_service 11.10.0 (15.0.0 available)
+ watcher 1.1.1
+ yaml 3.1.3
Building package executables... (1.7s)
Built interactive:interactive.
Installed executable interactive.
Activated interactive 1.4.1.
$ interactive
Run: /Users/beninato/fvm/versions/3.27.1/bin/cache/dart-sdk/bin/dart [--enable-vm-service=50212, file:///Users/beninato/.pub-cache/global_packages/interactive/bin/interactive.dart-3.6.0.snapshot, --vm-service-was-enabled]
Workspace: /var/folders/nd/yt3bmrtd4s3882h6n_sfn9tw0000gn/T/dart_interactive_workspace_2025-04-18T210650962449
The Dart VM service is listening on http://127.0.0.1:50212/h2EPiuuf_t8=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:50212/h2EPiuuf_t8=/devtools/?uri=ws://127.0.0.1:50212/h2EPiuuf_t8=/ws
$ dart --version 
Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "macos_arm64"

However, after running dart pub global deactivate interactive and dart pub global activate interactive, it seems to be working in iTerm2 (VS Code still was not working, so I'm not sure if the deactivate / activate was even needed to work on a different terminal)

Run: /Users/beninato/fvm/versions/3.27.1/bin/cache/dart-sdk/bin/dart [--enable-vm-service=52094, file:///Users/beninato/.pub-cache/global_packages/interactive/bin/interactive.dart-3.6.0.snapshot, --vm-service-was-enabled]
The Dart VM service is listening on http://127.0.0.1:52094/HOn98ypQ-bs=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:52094/HOn98ypQ-bs=/devtools/?uri=ws://127.0.0.1:52094/HOn98ypQ-bs=/ws
Workspace: /var/folders/nd/yt3bmrtd4s3882h6n_sfn9tw0000gn/T/dart_interactive_workspace_2025-04-18T211811585326
>>> print("hello world")
hello world
>>>

beninato8 avatar Apr 19 '25 04:04 beninato8

Can confirm the same issue when i install interactive using dart pub global activate interactive

  • M2 Max MBP (macos version 15.3.2 and 15.4.1) with Dart SDK version: 3.4.4, 3.5.4, and 3.7.2 (vscode terminal, ghostty, alacritty, and default macos terminal)

HP Ryzen Pro 5650U Windows laptop with dart 3.7.0 seems to work fine though.

When I download the repository on my MBP and run dart pub global activate --source path . to install interactive from a local repository, i get the following error, which might be helpful.

Unhandled exception:
getVM: (-32000) Service connection disposed
#0      VmService._call (package:vm_service/src/vm_service.dart:1912:7)
#1      VmService.getVM (package:vm_service/src/vm_service.dart:1388:25)
#2      _extension#0.getIsolateIds (package:interactive/src/workspace_isolate.dart:58:65)
#3      WorkspaceIsolate.create (package:interactive/src/workspace_isolate.dart:43:38)
<asynchronous suspension>
#4      Executor.create (package:interactive/src/executor.dart:41:30)
<asynchronous suspension>
#5      run (package:interactive/src/main.dart:59:7)
<asynchronous suspension>
#6      main (file://~/Downloads/dart_interactive-master/packages/interactive/bin/interactive.dart:9:5)
<asynchronous suspension>

However, when I run dart run bin/interactive.dart it works just fine. So something seems to be going on during compilation that causes the problem.

When I compile bin/interactive.dart to a kernel and run that, I get the same error message getVM: (-32000) Service connection disposed

When I compile to exe and run that I get the following infinite retry loop:

./interactive.exe
Run: ./interactive.exe [--enable-vm-service=53521,
	file://./interactive.exe, --vm-service-was-enabled]
Run: ./interactive.exe [--enable-vm-service=53522,
	file://./interactive.exe, --vm-service-was-enabled, --enable-vm-service=53521,
	file://./interactive.exe, --vm-service-was-enabled]
Run: ./interactive.exe [--enable-vm-service=53523,
	file://./interactive.exe, --vm-service-was-enabled, --enable-vm-service=53522,
	file://./interactive.exe, --vm-service-was-enabled, --enable-vm-service=53521,
	file://./interactive.exe, --vm-service-was-enabled]
Run: ./interactive.exe [--enable-vm-service=53524,
	file://./interactive.exe, --vm-service-was-enabled, --enable-vm-service=53523,
	file://./interactive.exe, --vm-service-was-enabled, --enable-vm-service=53522,
	file://./interactive.exe, --vm-service-was-enabled, --enable-vm-service=53521,
	file://./interactive.exe, --vm-service-was-enabled]

The pattern is that if it fails to run at a given port then it keeps trying one higher port number and then proceed to check every port below it until it reaches the default port number.

JordyScript avatar Apr 24 '25 21:04 JordyScript

For my personal use, I just hacked together a workaround solution:

  1. install interactive using dart pub global activate interactive
  2. download the interactive source code from github
  3. go to ~/.pub-cache/global_packages/interactive and delete its contents
  4. move bin, src, and pubspec.lock from the interactive repository into ~/.pub-cache/global_packages/interactive
  5. edit ~/.pub-cache/bin/interactive to contain the following command dart run ../global_packages/interactive/bin/interactive.dart "$@"

Not ideal, but functional. I guess the root cause is related to dart itself and not interactive, but fixing that is above my paygrade.

JordyScript avatar Apr 25 '25 14:04 JordyScript

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 24 '25 16:06 stale[bot]

Same problem here.

~ $ dart pub global activate interactive
Downloading packages... .
+ _fe_analyzer_shared 85.0.0 (86.0.0 available)
+ analyzer 7.7.0 (8.0.0 available)
+ args 2.7.0
+ async 2.13.0
+ cli_repl 0.2.3
+ collection 1.19.1
+ convert 3.1.2
+ crypto 3.0.6
+ file 7.0.1
+ glob 2.1.3
+ interactive 1.4.1
+ js 0.6.7 (0.7.2 available)
+ logging 1.3.0
+ meta 1.17.0
+ package_config 2.2.0
+ path 1.9.1
+ pub_semver 2.2.0
+ source_span 1.10.1
+ string_scanner 1.4.1
+ term_glyph 1.2.2
+ typed_data 1.4.0
+ vm_service 11.10.0 (15.0.2 available)
+ watcher 1.1.2
+ yaml 3.1.3
Building package executables... (5.5s)
Built interactive:interactive.
Installed executable interactive.
Activated interactive 1.4.1.
~ $ interactive
Run: dart [--enable-vm-service=42601, file:///ssd/ckchen/.pub-cache/global_packages/interactive/bin/interactive.dart-3.8.1.snapshot, --vm-service-was-enabled]
Workspace: /tmp/dart_interactive_workspace_2025-07-21T130411923433
The Dart VM service is listening on http://127.0.0.1:42601/O7ZpUJiL75A=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:42601/O7ZpUJiL75A=/devtools/?uri=ws://127.0.0.1:42601/O7ZpUJiL75A=/ws
^C
~ $ dart --version
Dart SDK version: 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "linux_x64"
~ $ uname -a
Linux cadpcd 5.15.0-139-generic #149~20.04.1-Ubuntu SMP Wed Apr 16 08:29:56 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
~ $

My temporary solution is, after dart pub global activate interactive, run dart pub global run interactive:interactive instead of interactive.

javaddict avatar Jul 21 '25 05:07 javaddict