jdx / mise

dev tools, env vars, task runner

Home Page:https://mise.jdx.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go and NPM backends behave weird on fresh systems

jimeh opened this issue · comments

Describe the bug

When using the Go and NPM backends, and mise to install the language runtime that the backend depend upon, you can get into a state where nearly all mise commands just instantly hang indefinitely.

In theory, simply running mise install twice should get everything installed. As first time around the backends which cannot be used will just be ignored, but language runtimes will be installed. And second time around the backends can find the tools they depend on, and also install all tools from the backends.

What actually happens with Go and NPM backends however, is that after the first mise install command that installs the language runtime, nearly all mise commands just hang indefinitely.

To Reproduce

I've prepared a little Docker-based environment where it's easy to reproduce this issue:

Dockerfile
FROM ubuntu:24.04
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && apt-get install --no-install-recommends -y \
    build-essential \
    ca-certificates \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

RUN curl https://mise.run | sh

# Activate mise.
RUN echo 'eval "$(~/.local/bin/mise activate bash)"' >> ~/.bashrc

# Alternatively, active mise with PATH modifications and using shims.
# RUN echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc \
#     && echo 'export PATH="$HOME/.local/share/mise/shims:$PATH"' >> ~/.bashrc

RUN mkdir -p /root/.config/mise
COPY config.toml /root/.config/mise/config.toml

WORKDIR /root
config.toml
[settings]
experimental = true

[tools]
go = "latest"
"go:golang.org/x/tools/gopls" = "latest"

# node = "lts"
# "npm:prettier" = "latest"

# rust = "latest"
# "cargo:cargo-binstall" = "latest"

To use it, simply run:

docker build -t mise-debug . && docker run --rm -it mise-debug bash

Trying to use mise like normal with go and a go:... in the config from the start, will lead to mise hanging after go is installed:

Example

config.toml:

[settings]
experimental = true

[tools]
go = "latest"
"go:golang.org/x/tools/gopls" = "latest"

Console:

root@1f6b3f9af1c0:~# mise ls
mise failed to resolve version of go:golang.org/x/tools/gopls from ~/.config/mise/config.toml: go is not installed. Please install it in order to install golang.org/x/tools/gopls
Plugin  Version           Config Source              Requested
go      1.22.3 (missing)  ~/.config/mise/config.toml latest
root@1f6b3f9af1c0:~# mise install
mise failed to resolve version of go:golang.org/x/tools/gopls from ~/.config/mise/config.toml: go is not installed. Please install it in order to install golang.org/x/tools/gopls
mise failed to resolve version of go:golang.org/x/tools/gopls from ~/.config/mise/config.toml: go is not installed. Please install it in order to install golang.org/x/tools/gopls
root@1f6b3f9af1c0:~# mise ls
^C

However, if you remove all go:... tools from config.toml, and start again, manually installing gopls with mise use after Go is already installed, it works fine:

Example

config.toml:

[settings]
experimental = true

[tools]
go = "latest"

Console:

root@3ff41afb9468:~# mise ls
Plugin  Version           Config Source              Requested
go      1.22.3 (missing)  ~/.config/mise/config.toml latest
root@3ff41afb9468:~# mise install
mise go@1.22.3 ✓ installed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         root@3ff41afb9468:~# mise use -g go:golang.org/x/tools/gopls
go: downloading golang.org/x/tools/gopls v0.15.3
go: downloading mvdan.cc/xurls/v2 v2.5.0
go: downloading honnef.co/go/tools v0.4.6
go: downloading golang.org/x/tools v0.18.1-0.20240412183611-d92ae0781217
go: downloading mvdan.cc/gofumpt v0.6.0
go: downloading golang.org/x/sync v0.6.0
go: downloading golang.org/x/vuln v1.0.1
go: downloading golang.org/x/telemetry v0.0.0-20240209200032-7b892fcb8a78
go: downloading golang.org/x/mod v0.15.0
go: downloading github.com/google/go-cmp v0.6.0
go: downloading golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338
go: downloading golang.org/x/text v0.14.0
go: downloading github.com/BurntSushi/toml v1.2.1
mise go:golang.org/x/tools/gopls@0.15.3 ✓ installed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                mise ~/.config/mise/config.toml tools: go:golang.org/x/tools/gopls@0.15.3
root@3ff41afb9468:~# which gopls
/root/.local/share/mise/shims/gopls
root@3ff41afb9468:~# mise ls
Plugin                       Version  Config Source              Requested
go                           1.22.3   ~/.config/mise/config.toml latest
go:golang.org/x/tools/gopls  0.15.3   ~/.config/mise/config.toml latest

It even keeps working after uninstalling gopls, and it still being listed in the config file:

Example

Console:

root@3ff41afb9468:~# mise uninstall go:golang.org/x/tools/gopls
mise go:golang.org/x/tools/gopls@0.15.3 ✓ uninstalled                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              root@3ff41afb9468:~# mise ls
Plugin                       Version           Config Source              Requested
go                           1.22.3            ~/.config/mise/config.toml latest
go:golang.org/x/tools/gopls  0.15.3 (missing)  ~/.config/mise/config.toml latest
root@3ff41afb9468:~# cat ~/.config/mise/config.toml
[settings]
experimental = true

[tools]
go = "latest"
"go:golang.org/x/tools/gopls" = "latest"

The exact same issue happens with the NPM backend as well.

But, it does not happen with the cargo backend, that works fine, with the only catch being you need to run mise install twice, as first time will install rust, and second time will all tools that use the cargo backend:

Example

config.toml:

[settings]
experimental = true

[tools]
rust = "latest"
"cargo:cargo-binstall" = "latest"

Console:

root@76b2a3b555f8:~# mise ls
mise failed to resolve version of cargo:cargo-binstall from ~/.config/mise/config.toml: cargo is not installed. Please install it in order to install cargo-binstall
Plugin  Version           Config Source              Requested
rust    latest (missing)  ~/.config/mise/config.toml latest
root@76b2a3b555f8:~# mise install
mise failed to resolve version of cargo:cargo-binstall from ~/.config/mise/config.toml: cargo is not installed. Please install it in order to install cargo-binstall
mise ⚠️  rust is a community-developed plugin
mise url: https://github.com/code-lever/asdf-rust
 Would you like to install rust? Yes
info: downloading installer
info: profile set to 'default'
info: default host triple is aarch64-unknown-linux-gnu
info: syncing channel updates for '1.78.0-aarch64-unknown-linux-gnu'
info: latest update on 2024-05-02, rust version 1.78.0 (9b00956e5 2024-04-29)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
info: default toolchain set to '1.78.0-aarch64-unknown-linux-gnu'
mise failed to resolve version of cargo:cargo-binstall from ~/.config/mise/config.toml: cargo is not installed. Please install it in order to install cargo-binstall
root@76b2a3b555f8:~# mise ls
Plugin                Version          Config Source              Requested
cargo:cargo-binstall  1.6.6 (missing)  ~/.config/mise/config.toml latest
rust                  1.78.0           ~/.config/mise/config.toml latest
root@76b2a3b555f8:~# mise install
    Updating crates.io index
 Downloading crates ...
  Downloaded cargo-binstall v1.6.6
  Installing cargo-binstall v1.6.6
    Updating crates.io index
 Downloading crates ...
[...]
    Finished `release` profile [optimized] target(s) in 45.44s
  Installing /root/.local/share/mise/installs/cargo-cargo-binstall/1.6.6/bin/cargo-binstall
   Installed package `cargo-binstall v1.6.6` (executable `cargo-binstall`)
warning: be sure to add `/root/.local/share/mise/installs/cargo-cargo-binstall/1.6.6/bin` to your PATH to be able to run the installed binaries
mise cargo:cargo-binstall@1.6.6 ✓ installed
root@76b2a3b555f8:~# mise ls
Plugin                Version  Config Source              Requested
cargo:cargo-binstall  1.6.6    ~/.config/mise/config.toml latest
rust                  1.78.0   ~/.config/mise/config.toml latest

Expected behavior

That mise does not get into a state where all commands hang indefinitely. If your shell prompt depends on running anything related to mise, it can get somewhat painful to resolve the issue.

mise doctor output

Before installing `go`
version: 2024.5.5 linux-arm64 (7e8dab5 2024-05-12)
activated: no
shims_on_path: yes

build_info:
  Target: aarch64-unknown-linux-gnu
  Features: DEFAULT, GIT2, NATIVE_TLS, OPENSSL
  Built: Sun, 12 May 2024 00:57:45 +0000
  Rust Version: rustc 1.78.0 (9b00956e5 2024-04-29)
  Profile: release

shell:
  (unknown)

dirs:
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/.cache/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files:
  ~/.config/mise/config.toml

backends:
  cargo
  go
  npm
  pipx
  ubi

plugins:
  bun     (core)
  deno    (core)
  erlang  (core)
  go      (core)
  java    (core)
  node    (core)
  python  (core)
  ruby    (core)
  zig     (core)
mise failed to resolve version of go:golang.org/x/tools/gopls from ~/.config/mise/config.toml: go is not installed. Please install it in order to install golang.org/x/tools/gopls

toolset:
  go@1.22.3  (missing)

env_vars:
  (none)

settings:
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cargo_binstall = true
  color = true
  disable_default_shorthands = false
  disable_tools = []
  experimental = true
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  node_compile = false
  not_found_auto_install = true
  paranoid = false
  plugin_autoupdate_last_check_duration = "7d"
  python_compile = false
  python_default_packages_file = "/root/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  raw = false
  trusted_config_paths = []
  quiet = false
  verbose = false
  yes = false
  ci = false
  debug = false
  trace = false
  log_level = "info"
  python_venv_auto_create = false

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false

No warnings found
No problems found
After installing `go`, `mise doctor` hangs half-way through
version: 2024.5.5 linux-arm64 (7e8dab5 2024-05-12)
activated: yes
shims_on_path: no

build_info:
  Target: aarch64-unknown-linux-gnu
  Features: DEFAULT, GIT2, NATIVE_TLS, OPENSSL
  Built: Sun, 12 May 2024 00:57:45 +0000
  Rust Version: rustc 1.78.0 (9b00956e5 2024-04-29)
  Profile: release

shell:
  bash
  GNU bash, version 5.2.21(1)-release (aarch64-unknown-linux-gnu)
  Copyright (C) 2022 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

dirs:
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/.cache/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files:
  ~/.config/mise/config.toml

backends:
  cargo
  go
  npm
  pipx
  ubi

plugins:
  bun     (core)
  deno    (core)
  erlang  (core)
  go      (core)
  java    (core)
  node    (core)
  python  (core)
  ruby    (core)
  zig     (core)

Additional context

N/A

I have a fix ready but it still could be improved. It won't install the dependency at the same time, so you need to run mise install twice, but at least it isn't locking up anymore.

Awesome, multiple invocations of mise install is more than fine by me :)