ruby-lsp-rails icon indicating copy to clipboard operation
ruby-lsp-rails copied to clipboard

Rogue ruby-lsp related processes even after VS Code is quit

Open tisba opened this issue 1 year ago • 18 comments

Description

From time to time I notice that there are a bunch of ruby processes where I'm pretty sure they are related to ruby-lsp even if the Rails project got already closed or VS Code is no longer running (see details below).

Ruby LSP Information

VS Code Version

1.95.2

Ruby LSP Extension Version

0.8.13

Ruby LSP Server Version

0.21.3

Ruby LSP Addons

  • Ruby LSP Rails

Ruby Version

3.3.5

Ruby Version Manager

chruby

Installed Extensions

Click to expand
  • EditorConfig (0.16.4)
  • code-spell-checker (3.0.1)
  • copilot (1.243.0)
  • copilot-chat (0.22.2)
  • debugpy (2024.12.0)
  • dotenv (1.0.1)
  • even-better-toml (0.19.2)
  • go (0.42.1)
  • haml (1.4.1)
  • makefile-tools (0.11.13)
  • prettier-vscode (11.0.0)
  • python (2024.18.0)
  • remote-containers (0.388.0)
  • remote-explorer (0.4.3)
  • remote-server (1.5.2)
  • remote-ssh (0.115.0)
  • remote-ssh-edit (0.87.0)
  • remote-wsl (0.88.5)
  • rewrap (1.16.3)
  • ruby-extensions-pack (0.1.12)
  • ruby-lsp (0.8.13)
  • rust-analyzer (0.3.2172)
  • shellcheck (0.37.1)
  • solargraph (0.24.1)
  • sorbet-vscode-extension (0.3.37)
  • vscode-docker (1.29.3)
  • vscode-eslint (3.0.10)
  • vscode-fileutils (3.10.3)
  • vscode-github-actions (0.27.0)
  • vscode-graphviz (0.0.9)
  • vscode-kubernetes-tools (1.3.18)
  • vscode-markdownlint (0.56.0)
  • vscode-proto3 (0.5.5)
  • vscode-rdbg (0.2.2)
  • vscode-remote-extensionpack (0.26.0)
  • vscode-standard (2.1.3)
  • vscode-todo-highlight (1.0.5)
  • vscode-typescript-next (5.8.20241106)
  • vscode-yaml (1.15.0)
  • vsliveshare (1.0.5941)

Ruby LSP Settings

Click to expand
Workspace
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  }
}
User
{
  "enableExperimentalFeatures": true,
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "chruby"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "useLauncher": false,
  "featureFlags": {}
}

Reproduction steps

Unavailable at this time.

I'm not sure if there is something specific I'm doing that leads to the issue. From time to time I just notice that there are a bunch of ruby processes running where I'm either 100% sure (~/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/server.rb) or pretty sure (~/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch […]) that they are spawned/related to ruby-lsp. I'm only using ruby-lsp from within VSCode.

There must be something off with process cleanup. Especially after quitting VS Code I'd expect all spawned processes to be properly terminated.

This output is from VS Code being terminated (properly quit, closing all windows before, no crashes reported, etc) – ps aux:

tisba            69979   0.0  0.0 410170688   1776   ??  S    Wed06PM   0:01.48 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/lib /Users/tisba/src/rails_project/spec/mailers/previews /Users/tisba/src/rails_project/app/controllers /Users/tisba/src/rails_project/app/decorators /Users/tisba/src/rails_project/app/helpers /Users/tisba/src/rails_project/app/lib /Users/tisba/src/rails_project/app/mailers /Users/tisba/src/rails_project/app/models /Users/tisba/src/rails_project/app/sandbox /Users/tisba/src/rails_project/app/serializers /Users/tisba/src/rails_project/app/validators /Users/tisba/src/rails_project/db
tisba            69978   0.0  0.0 410190144   1472   ??  S    Wed06PM   0:01.37 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/app/views
tisba            69977   0.0  0.0 410163520   1376   ??  S    Wed06PM   0:01.31 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/spec/factories
tisba            69976   0.0  0.0 410171712   1504   ??  S    Wed06PM   0:01.48 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/config/locales
tisba            69975   0.0  0.0 411842656   4144   ??  Ss   Wed06PM   0:00.62 /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/server.rb
tisba            69974   0.0  0.0 411361424   3520   ??  S    Wed06PM   0:00.39 /Users/tisba/.rubies/ruby-3.3.5/bin/ruby bin/rails runner /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/server.rb start
tisba            69929   0.0  0.0 412429648   3584   ??  S    Wed06PM   0:07.84 /Users/tisba/.gem/ruby/3.3.5/bin/ruby-lsp
tisba            59817   0.0  0.0 410171712   1776   ??  S    Wed03PM   0:01.82 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/lib /Users/tisba/src/rails_project/spec/mailers/previews /Users/tisba/src/rails_project/app/controllers /Users/tisba/src/rails_project/app/decorators /Users/tisba/src/rails_project/app/helpers /Users/tisba/src/rails_project/app/lib /Users/tisba/src/rails_project/app/mailers /Users/tisba/src/rails_project/app/models /Users/tisba/src/rails_project/app/sandbox /Users/tisba/src/rails_project/app/serializers /Users/tisba/src/rails_project/app/validators /Users/tisba/src/rails_project/db
tisba            59816   0.0  0.0 410173760   1472   ??  S    Wed03PM   0:01.64 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/app/views
tisba            59815   0.0  0.0 410179904   1776   ??  S    Wed03PM   0:01.81 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/lib /Users/tisba/src/rails_project/spec/mailers/previews /Users/tisba/src/rails_project/app/controllers /Users/tisba/src/rails_project/app/decorators /Users/tisba/src/rails_project/app/helpers /Users/tisba/src/rails_project/app/lib /Users/tisba/src/rails_project/app/mailers /Users/tisba/src/rails_project/app/models /Users/tisba/src/rails_project/app/sandbox /Users/tisba/src/rails_project/app/serializers /Users/tisba/src/rails_project/app/validators /Users/tisba/src/rails_project/db
tisba            59814   0.0  0.0 410173760   1472   ??  S    Wed03PM   0:01.66 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/app/views
tisba            59813   0.0  0.0 410182976   1376   ??  S    Wed03PM   0:01.76 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/spec/factories
tisba            59812   0.0  0.0 410163520   1504   ??  S    Wed03PM   0:01.69 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/config/locales
tisba            59811   0.0  0.0 411842496   3888   ??  Ss   Wed03PM   0:00.64 /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/server.rb
tisba            59810   0.0  0.0 410164544   1376   ??  S    Wed03PM   0:02.07 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/spec/factories
tisba            59809   0.0  0.0 410173760   1504   ??  S    Wed03PM   0:02.13 /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/src/rails_project/config/locales
tisba            59728   0.0  0.0 411212880   3280   ??  S    Wed03PM   0:00.38 /Users/tisba/.rubies/ruby-3.3.5/bin/ruby bin/rails runner /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/server.rb start
tisba            59599   0.0  0.0 412176912   3584   ??  S    Wed03PM   0:09.46 /Users/tisba/.gem/ruby/3.3.5/bin/ruby-lsp

tisba avatar Nov 08 '24 11:11 tisba

:wave: There are various things that could potentially cause this, but we'd really need a consistent reproduction case to investigate.

(btw I corrected the spelling in the PR title to make it easier to search for this issue).

andyw8 avatar Nov 08 '24 13:11 andyw8

👋 There are various things that could potentially cause this, but we'd really need a consistent reproduction case to investigate.

Yeah, I figured as much. I'm not sure I have seen a consistent pattern yet. These processes don't seem to cause issues and are not consuming enough resources to be noticeable right away. I'm trying to think of something to detect this sooner so I can relate that to something I'm doing.

To the point of processes running after VS Code has been terminated: Isn't there a mechanism to ensure that child processes are properly terminated? Depending on how the extension spawns those children that should be something that happens automatically by the OS, right? 🤔

(btw I corrected the spelling in the PR title to make it easier to search for this issue).

Thank you 🙈

tisba avatar Nov 08 '24 13:11 tisba

To the point of processes running after VS Code has been terminated: Isn't there a mechanism to ensure that child processes are properly terminated? Depending on how the extension spawns those children that should be something that happens automatically by the OS, right? 🤔

Here's what we do on shutdown:

https://github.com/Shopify/ruby-lsp-rails/blob/6580aa6eb7cd7f8f61502488f81c63c00ce3d894/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb#L95-L102

andyw8 avatar Nov 08 '24 13:11 andyw8

Disclaimer: I have almost no idea how VS Code extensions or ruby-lsp is structured, so bare with me :)

My current theory is that VS Code's Code Helper (Plugin) process crashes (which actually happens some times for me). Looking at the process tree, it looks like ruby-lsp processes are children of that process:

-+= 50801 tisba /Applications/Visual Studio Code.app/Contents/MacOS/Electron
 |--- 50802 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (GPU).app/Contents/MacOS/Code Helper (GPU) --type=gpu-process --user-data-dir=/Users/tisba/Library/Application Support/Code --gpu-preferences=UAAAAAAAAAAgAAAEAAAAAAAAAAAAAAAAAABgAAEAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAA --shared-files --field-trial-handle=1718379636,r,15518530713489516058,4187484149676038975,262144 --enable-features=ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma --disable-features=CalculateNativeWinOcclusion,MacWebContentsOcclusion,SpareRendererForSitePerProcess,TimeoutHangingVideoCaptureStarts --variations-seed-version --seatbelt-client=30
 |--- 50803 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --user-data-dir=/Users/tisba/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files --field-trial-handle=1718379636,r,15518530713489516058,4187484149676038975,262144 --enable-features=ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma --disable-features=CalculateNativeWinOcclusion,MacWebContentsOcclusion,SpareRendererForSitePerProcess,TimeoutHangingVideoCaptureStarts --variations-seed-version --seatbelt-client=30
 |--- 50805 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) --type=renderer --user-data-dir=/Users/tisba/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --app-path=/Applications/Visual Studio Code.app/Contents/Resources/app --enable-sandbox --enable-blink-features=HighlightAPI --disable-blink-features=FontMatchingCTMigration, --lang=en-US --num-raster-threads=4 --enable-zero-copy --enable-gpu-memory-buffer-compositor-resources --enable-main-frame-before-activation --renderer-client-id=4 --time-ticks-at-unix-epoch=-1730984992351564 --launch-time-ticks=167985976350 --shared-files --field-trial-handle=1718379636,r,15518530713489516058,4187484149676038975,262144 --enable-features=ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma --disable-features=CalculateNativeWinOcclusion,MacWebContentsOcclusion,SpareRendererForSitePerProcess,TimeoutHangingVideoCaptureStarts --variations-seed-version --vscode-window-config=vscode:bd6ed9f8-a918-4e68-b2c1-416cb35bd806 --seatbelt-client=64
 |--- 50859 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --user-data-dir=/Users/tisba/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files --field-trial-handle=1718379636,r,15518530713489516058,4187484149676038975,262144 --enable-features=ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma --disable-features=CalculateNativeWinOcclusion,MacWebContentsOcclusion,SpareRendererForSitePerProcess,TimeoutHangingVideoCaptureStarts --variations-seed-version
 |--- 50860 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --user-data-dir=/Users/tisba/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files --field-trial-handle=1718379636,r,15518530713489516058,4187484149676038975,262144 --enable-features=ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma --disable-features=CalculateNativeWinOcclusion,MacWebContentsOcclusion,SpareRendererForSitePerProcess,TimeoutHangingVideoCaptureStarts --variations-seed-version
 \-+- 50900 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --dns-result-order=ipv4first --inspect-port=0 --user-data-dir=/Users/tisba/Library/Application Support/Code --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --code-cache-schemes=vscode-webview,vscode-file --shared-files --field-trial-handle=1718379636,r,15518530713489516058,4187484149676038975,262144 --enable-features=ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma --disable-features=CalculateNativeWinOcclusion,MacWebContentsOcclusion,SpareRendererForSitePerProcess,TimeoutHangingVideoCaptureStarts --variations-seed-version
   |-+= 51048 tisba /Users/tisba/.gem/ruby/3.3.5/bin/ruby-lsp    
   | \-+- 51067 tisba /Users/tisba/.rubies/ruby-3.3.5/bin/ruby bin/rails runner /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/server.rb start
   |   \-+- 51071 tisba spring server | forge | started 13 mins ago   
   |     \-+= 51072 tisba spring app    | forge | started 13 mins ago | development mode      
   |       |--- 51118 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/config/locales
   |       |--- 51119 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/spec/factories
   |       |-+= 51120 tisba /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/server.rb      
   |       | |--- 51121 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/config/locales
   |       | |--- 51122 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/spec/factories
   |       | |--- 51126 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/app/views
   |       | \--- 51129 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/lib /Users/tisba/Documents/work/rails-app/spec/mailers/previews /Users/tisba/Documents/work/rails-app/app/controllers /Users/tisba/Documents/work/rails-app/app/decorators /Users/tisba/Documents/work/rails-app/app/helpers /Users/tisba/Documents/work/rails-app/app/lib /Users/tisba/Documents/work/rails-app/app/mailers /Users/tisba/Documents/work/rails-app/app/models /Users/tisba/Documents/work/rails-app/app/sandbox /Users/tisba/Documents/work/rails-app/app/serializers /Users/tisba/Documents/work/rails-app/app/validators /Users/tisba/Documents/work/rails-app/db
   |       |--- 51123 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/app/views
   |       \--- 51125 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/lib /Users/tisba/Documents/work/rails-app/spec/mailers/previews /Users/tisba/Documents/work/rails-app/app/controllers /Users/tisba/Documents/work/rails-app/app/decorators /Users/tisba/Documents/work/rails-app/app/helpers /Users/tisba/Documents/work/rails-app/app/lib /Users/tisba/Documents/work/rails-app/app/mailers /Users/tisba/Documents/work/rails-app/app/models /Users/tisba/Documents/work/rails-app/app/sandbox /Users/tisba/Documents/work/rails-app/app/serializers /Users/tisba/Documents/work/rails-app/app/validators /Users/tisba/Documents/work/rails-app/db
   |--- 51056 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/tisba/.vscode/extensions/github.vscode-github-actions-0.27.0/dist/server-node.js --node-ipc --clientProcessId=50900
   |--- 51073 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/tisba/.vscode/extensions/streetsidesoftware.code-spell-checker-3.0.1/packages/_server/dist/main.cjs --node-ipc --clientProcessId=50900
   |--- 51127 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/tisba/.vscode/extensions/dbaeumer.vscode-eslint-3.0.10/server/out/eslintServer.js --node-ipc --clientProcessId=50900
   \--- 51128 tisba /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=50900

When I kill pid 50900 to simulate a "hard crash" of the helper process, 51071 gets adopted by launchd:

-+- 51071 tisba spring server | forge | started 17 mins ago   
 \-+= 51072 tisba spring app    | forge | started 17 mins ago | development mode      
   |--- 51118 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/config/locales
   |--- 51119 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/spec/factories
   |--- 51123 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/app/views
   |--- 51125 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/lib /Users/tisba/Documents/work/rails-app/spec/mailers/previews /Users/tisba/Documents/work/rails-app/app/controllers /Users/tisba/Documents/work/rails-app/app/decorators /Users/tisba/Documents/work/rails-app/app/helpers /Users/tisba/Documents/work/rails-app/app/lib /Users/tisba/Documents/work/rails-app/app/mailers /Users/tisba/Documents/work/rails-app/app/models /Users/tisba/Documents/work/rails-app/app/sandbox /Users/tisba/Documents/work/rails-app/app/serializers /Users/tisba/Documents/work/rails-app/app/validators /Users/tisba/Documents/work/rails-app/db
   \-+= 65775 tisba /Users/tisba/.gem/ruby/3.3.5/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/server.rb      
     |--- 65776 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/config/locales
     |--- 65777 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/spec/factories
     |--- 65778 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/app/views
     \--- 65779 tisba /Users/tisba/.gem/ruby/3.3.5/gems/rb-fsevent-0.11.2/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/tisba/Documents/work/rails-app/lib /Users/tisba/Documents/work/rails-app/spec/mailers/previews /Users/tisba/Documents/work/rails-app/app/controllers /Users/tisba/Documents/work/rails-app/app/decorators /Users/tisba/Documents/work/rails-app/app/helpers /Users/tisba/Documents/work/rails-app/app/lib /Users/tisba/Documents/work/rails-app/app/mailers /Users/tisba/Documents/work/rails-app/app/models /Users/tisba/Documents/work/rails-app/app/sandbox /Users/tisba/Documents/work/rails-app/app/serializers /Users/tisba/Documents/work/rails-app/app/validators /Users/tisba/Documents/work/rails-app/db

So bin/ruby-lsp is terminated, but spring and its children keep running, which is kind of the point of spring. So I guess this is an issue with ruby-lsp in combination with spring. If I comment out spring in bin/rails and repeat the SIGKILL on the plugin helper it works as expected, no left over processed adopted by launchd:

#!/usr/bin/env ruby
# load File.expand_path("spring", __dir__)
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands"

That might be worth something for the troubleshooting guide, or maybe https://github.com/Shopify/ruby-lsp-rails/blob/6580aa6eb7cd7f8f61502488f81c63c00ce3d894/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb#L74-L76 could set DISABLE_SPRING=1? Alternatively is there a way to detect that ruby-lsp is running bin/rails, like an environment variable? That way one could disable spring if you don't want to make ruby-lsp aware of spring itself.

tisba avatar Nov 09 '24 12:11 tisba

While not very elegant, adding this to bin/rails works for now:

unless ENV.keys.none? { |k| k.include?("VSCODE") }
  load File.expand_path("spring", __dir__)
end

If there is a more elegant solution, I'm all ears :)

ADDED This has of course the downside, that the integrated VS Code terminal won't use spring either :(

tisba avatar Nov 21 '24 07:11 tisba

(moving to the rails-lsp-rails repo as this seems specific to that add-on)

andyw8 avatar Nov 21 '24 17:11 andyw8

@tisba on #555, which is released on v0.3.30, we started disabling view file watchers because we noticed considerable overhead coming from them. Plus, the LSP already watches files, so the work was duplicated anyway.

Do you still see the same after that version? Just trying to confirm that this is indeed related to Spring as I'm not sure exactly what piece of Rails spawns the fsevent_watch process.

vinistock avatar Jan 23 '25 14:01 vinistock

The picture is a little different now (sorry, don't have much time to investigate further). When the VS Code helper process crashes (or I kill it) and then quit VS Code, there are still some leftover processes that point to ruby-lsp, specifically this one:

bin/rails runner /Users/basti/.gem/ruby/3.4.1/gems/ruby-lsp-rails-0.4.0/lib/ruby_lsp/ruby_lsp_rails/server.rb start {"supports_progress":true}

As before, they get adopted by launchd and were before started by spring. I still think there should be a way to disable spring entirely.

tisba avatar Feb 21 '25 17:02 tisba

FWIW, I'm seeing the same problem with Neovim. When I quit Neovim, I see leftover processes:

$ ps aux | rg ruby_lsp_rails
pedro            61157   1.5  0.0 410730576   4032 s003  S+    9:49AM   0:00.01 rg ruby_lsp_rails
pedro            61052   0.0  0.2 411620400  16160   ??  S     9:49AM   0:00.47 /Users/pedro/.local/share/mise/installs/ruby/3.4.2/bin/ruby bin/rails runner /Users/pedro/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/ruby-lsp-rails-0.4.0/lib/ruby_lsp/ruby_lsp_rails/server.rb start {"supports_progress":true}
pedro            60317   0.0  0.1 411324464   5200   ??  S     9:47AM   0:00.47 /Users/pedro/.local/share/mise/installs/ruby/3.4.2/bin/ruby bin/rails runner /Users/pedro/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/ruby-lsp-rails-0.4.0/lib/ruby_lsp/ruby_lsp_rails/server.rb start {"supports_progress":true}

pedropombeiro avatar Feb 22 '25 08:02 pedropombeiro

I'm curious. Are you also using spring, @pedropombeiro?

tisba avatar Feb 22 '25 08:02 tisba

@tisba I am.

pedropombeiro avatar Feb 22 '25 08:02 pedropombeiro

Yeah, spring seems to be the culprit here. I stopped it, retried, and now the server process exits as expected.

pedropombeiro avatar Feb 22 '25 08:02 pedropombeiro

Yeah, so this is essentially #571. The Spring instance started by the Rails add-on will also be reused by any commands you run in the terminal.

The main issue is that Spring uses the process group ID to "attach" itself to the terminal and once you close it, the Spring process is also terminated. We made an attempt to produce the same effect here, but it's not working as expected.

vinistock avatar Feb 25 '25 14:02 vinistock

I personally would already be happy with an option to easily disable spring with ruby-lsp. Setting DISABLE_SPRING should already do the trick.

Implementing this correct while still using spring sounds very tricky for ruby-lsp. The whole point of spring is to keep these processes detached and running in the first place. spring already has some quirks when "used directly", but in context of ruby-lsp this will only get worse I imagine.

tisba avatar Feb 25 '25 14:02 tisba

Yeah. The only downside is that for very large apps, Spring makes a considerable difference in the time it takes for us to boot our little custom server.

Maybe there's a way to ensure that Spring gets terminated when the runtime server does.

vinistock avatar Feb 25 '25 14:02 vinistock

Yeah. The only downside is that for very large apps, Spring makes a considerable difference in the time it takes for us to boot our little custom server.

Agreed. That's why I said, it would be nice to have the option to disable it if it causes problems and/or your code base is not that large so it would matter. It also doesn't matter so much as starting the ruby-lsp server is a long running process. spring is especially nice for more interactive commands (IMO).

Maybe there's a way to ensure that Spring gets terminated when the runtime server does.

That would defeat the purpose of spring. The whole point of spring is to keep a warm process up and running.

To improve compatibility, you would need to find a more active way to cleanly shutdown processes that ruby-lsp starts, which does not rely on the process group exiting. I don't know enough about how VS Code / ruby-lsp works, but maybe some kind of deadman switch or something? If the started custom server would should itself down, then it's totally fine if spring keeps running. IMO, this is considered expected behavior if you choose to use spring in the first place.

tisba avatar Feb 25 '25 15:02 tisba

Just wanted to chime in that I’m experiencing the same issue when using Zed. As of writing this, I still have many ruby-lsp processes from yesterday that haven’t terminated.

I’m also encountering long delays when saving files—formatting tries to run but never completes. I believe the two issues are related. When I first start the editor and only one ruby-lsp process is active, formatting happens quickly. This problem also occurred when I was using VS Code a few months ago. One of the reasons I switched to Zed was because it seemed to handle this bug more gracefully.

This is in a fairly large Rails application.

❯ ps aux | rg ruby-lsp
stevegodin       67757  97.6  0.0 413407664   2192   ??  R    21May25 16826:42.79 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       18869  97.0  0.0 413437424   2176   ??  R    23May25 14691:01.67 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       39523  96.8  0.0 413350576   2160   ??  R    21May25 17157:03.89 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       36560  96.7  0.0 413376432   2160   ??  R    22May25 15973:34.12 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       26962  96.7  0.0 413333024   2208   ??  R    Thu08AM 7092:41.97 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       77119  96.7  0.0 413372144   2176   ??  R    20May25 17233:29.77 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       65632  96.7  0.0 413489648   2208   ??  R    Fri07AM 5657:43.25 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       43363  96.6  0.0 413431920   2160   ??  R    20May25 18164:22.31 /Users/stevegodin/.asdf/installs/ruby/3.3.5/bin/ruby-lsp
stevegodin       65740   0.0  0.0 412929616   5184   ??  S    Fri07AM   1:48.11 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       27094   0.0  0.0 412909424   5296   ??  S    Thu08AM   2:13.19 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       18881   0.0  0.0 412911216   5088   ??  S    23May25   3:58.14 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       36586   0.0  0.0 412907760   5168   ??  S    22May25   4:18.17 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       67827   0.0  0.0 412913264   5152   ??  S    21May25   4:24.62 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       39838   0.0  0.0 412907952   4992   ??  S    21May25   4:25.09 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       77431   0.0  0.0 412908848   5168   ??  S    20May25   4:26.34 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb
stevegodin       43403   0.0  0.0 412914800   5152   ??  S    20May25   4:25.38 /Users/stevegodin/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.4.3/lib/ruby_lsp/ruby_lsp_rails/server.rb

whilestevego avatar Jun 04 '25 13:06 whilestevego

Are you able to reproduce this reliably? If you tell the LSP to restart, do you always get a lingering process afterwards?

If so, it would be nice to trace what's happening that's preventing the LSP from shutting down.

vinistock avatar Jun 18 '25 20:06 vinistock