rbenv activation leaks RBENV_VERSION and RBENV_DIR into process.env of the extension host
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- ruby, typescript, vscode
- Ambito
- devtools
Direzione di ricerca
Start in vscode/src/ruby.ts, where the activated environment is assigned to process.env, and in sanitizeEnvironment, which filters the dump from rbenv exec (vscode/src/ruby/rbenv.ts). Also check versionManager.ts, where the activation script is spawned with env: process.env. Done means RBENV_VERSION and RBENV_DIR no longer reach process.env after activation, while the Ruby LSP server still gets the rbenv-selected environment. Choosing between the three proposed fixes is a maintainer decision, so ask before committing to one.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
After Ruby activation, the extension replaces the environment of the whole extension host:
With rbenv, env is the environment of rbenv exec ruby
(rbenv.ts).
rbenv exec exports its internal variables to the child process, so the dump contains:
RBENV_VERSION=4.0.6
RBENV_DIR=/path/to/first/workspace
RBENV_HOOK_PATH=...
RBENV_ORIG_PATH=...
sanitizeEnvironment removes only RUBY_GC*, VERBOSE and DEBUG, so these variables end up in
process.env. rbenv gives RBENV_VERSION priority over .ruby-version, and it looks for
.ruby-version from RBENV_DIR rather than from the current directory. Every process started from
the extension host after activation is therefore pinned to the Ruby version and the folder of the
first activation.
Impact
-
Other extensions. All extensions share one extension host. A CLI that another extension
starts inherits the pinned version. We hit this with the Claude Code extension: its CLI, and every
shell it opens, hadRBENV_VERSIONset. After a Ruby bump in.ruby-version, Bundler fails with
Your Ruby version is X, but your Gemfile specified Yuntil VS Code restarts. The integrated
terminal is not affected, because it does not start from the extension host. That made the cause
hard to find. -
Ruby LSP itself. Activation spawns the activation script with
env: process.env
(versionManager.ts). After the first activation,process.envalready holdsRBENV_VERSION, so
a laterrbenv exec rubygets the old version. From reading the code, we expect this for:- a second folder of a multi-root workspace with a different
.ruby-version, - "Ruby LSP: Restart" after a change of
.ruby-version.
We did not run these two cases ourselves. #3270 reports the same Bundler error with rbenv,
including in a multi-root workspace. - a second folder of a multi-root workspace with a different
Steps to reproduce
- Use rbenv, and open a project with a
.ruby-versionin VS Code with Ruby LSP. - Wait until Ruby LSP activates Ruby.
- Start a process from another extension (for example, the Claude Code extension) and run
env | grep RBENV.
Expected: no RBENV_VERSION or RBENV_DIR. rbenv selects the version from .ruby-version of
the current directory.
Actual: RBENV_VERSION and RBENV_DIR hold the values of the first activation.
Proposed fix
One of these, from the smallest change to the cleanest:
- Delete the version manager internals in
sanitizeEnvironment:RBENV_VERSION,RBENV_DIR,
RBENV_HOOK_PATHandRBENV_ORIG_PATH. Other managers can have similar variables. - Copy only the variables that other extensions need into
process.env:PATH,GEM_HOMEand
GEM_PATH. - Remove the global assignment, and keep the activated environment for the Ruby LSP server only.
In #1997, the global assignment was called "simply the easiest option" while the integrations mature.
Option 1 or 2 keeps that purpose and removes the leak.
Related
- #1997: the same
process.envassignment brokePATHfor other extensions with asdf. - #3270: stray
RBENV_VERSIONand a Bundler version mismatch with rbenv. - Shopify/vscode-ruby-lsp#699: introduced the assignment (Shadowenv only).
- #1438, #1502: applied it to all version managers. #1811: rbenv uses the same path.
Environment
- Ruby LSP extension 0.10.6 (the code on
mainatc6aec8cbb2is the same) - VS Code 1.141.1
- rbenv 1.3.2
- macOS 26
- Workaround: set
RBENV_VERSION=""andRBENV_DIR=""in the environment of the affected tool.
rbenv treats an empty value as unset.
- Lingua principale
- Ruby
- Stelle
- 2k
- Fork
- 283
- Merge medio
- 9h 18m
- PR unite (30g)
- 11
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Shopify/ruby-lsp
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memoryForse già presa @efegokdemir l’ha presa 9 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Linux file system with square brackets in the directory/filename are failing to be indexedForse già presa @andriytyurnikov l’ha presa 213 giorni fa. Apertabug help-wanted pinned
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Shopify/ruby-lsp#3503 · 8 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Rename of a class moves its file and leaves require_relative on the old pathForse già presa @efegokdemir l’ha presa 10 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
I maintainer di solito rispondono entro 1 giorno
-
Paths need to be escapedForse già presa @Vraiment l’ha presa 14 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
check-labels intermittently fails due to the organization IP allow listForse già presa @soutaro l’ha presa 17 giorni fa. Aperta
Shopify/ruby-lsp#4219 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Shopify/ruby-lsp
Issue simili
-
Unconfirmed users who reset their password are stuck on sign in with no way to send confirmationAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
L: github:actions L: javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
dependabot/dependabot-core#16615 ·
I maintainer di solito rispondono entro 1 giorno
-
Kanton Column not HiddenApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
hitobito/hitobito_pfadi_de#164 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 7 giorni