-
Notifications
You must be signed in to change notification settings - Fork 233
Open
Labels
bugSomething isn't workingSomething isn't workingneeds-more-infoMore information is needed to address this issueMore information is needed to address this issue
Description
Description
Description
Ruby LSP crashes with SystemStackError: stack level too deep when processing method completion requests in Rails projects that contain circular method aliases. The crash occurs during autocomplete (typing . after an object) and makes the LSP server completely unresponsive.
Environment
- Ruby LSP Version: 0.26.4
- Ruby LSP Rails Version: 0.4.8
- Ruby Version: 3.3.3
- Rails Version: 8.1.1
- RuboCop Version: 1.82.1
- Operating System: macOS
- Editor: VS Code with Ruby LSP extension
Steps to Reproduce
- Create a Rails project with Ruby LSP 0.26.4 installed
- Open any Ruby file in VS Code
- Type . after any object to trigger autocomplete
- Ruby LSP server hangs and becomes unresponsive
Actual Behavior
- Ruby LSP server enters infinite recursion
- VS Code shows notification: "Getting code actions from 'Ruby LSP'" that runs indefinitely
- CPU usage spikes to 90-100% for the ruby-lsp process
- After ~10 seconds, crash with SystemStackError: stack level too deep
- LSP server becomes unresponsive and must be restarted
Error Log:
SystemStackError: stack level too deep
from ruby_indexer/lib/ruby_indexer/entry.rb:65:in `parse_file_comments'
from ruby_indexer/lib/ruby_indexer/entry.rb:65:in `comments'
from ruby_indexer/lib/ruby_indexer/entry.rb:456:in `initialize'
from ruby_indexer/lib/ruby_indexer/index.rb:1066:in `new'
from ruby_indexer/lib/ruby_indexer/index.rb:1066:in `resolve_method_alias'
from ruby_indexer/lib/ruby_indexer/index.rb:259:in `block in method_completion_candidates'
from ruby_indexer/lib/ruby_indexer/index.rb:231:in `each'
from ruby_indexer/lib/ruby_indexer/index.rb:231:in `each_with_object'
from ruby_indexer/lib/ruby_indexer/index.rb:231:in `method_completion_candidates'
... 8 levels...
from ruby_lsp/server.rb:936:in `text_document_completion'
Expected Behavior
- Ruby LSP should detect circular method aliases
- Autocomplete should work without hanging
- No stack overflow errors
- LSP server remains responsive
Root Cause Analysis
The bug occurs in the alias resolution logic within the method completion system. Here's the execution flow:
The following infinite loop occurs:
method_completion_candidates(line 259) callsresolve_method_alias(entry, receiver_name, [])resolve_method_alias(line 1066)creates Entry::MethodAlias.new(target, entry)MethodAlias.initialize(line 456) callstarget.commentscommentsmethod (line 65) callsPrism.parse_file_comments(path)which re-parses the file- Re-parsing discovers the reverse alias, triggering another call to
resolve_method_aliaswith emptyseen_namesagain - Loop continues infinitely until stack overflow
The Problem:
File: lib/ruby_indexer/lib/ruby_indexer/index.rb
# Line 259 - Inside method_completion_candidates
if entry.is_a?(Entry::UnresolvedMethodAlias)
resolved_alias = resolve_method_alias(entry, receiver_name, [])
^^
EMPTY ARRAY!
endWorkaround (For Users)
Until this is fixed, users can disable the completion feature to avoid the crash:
In .vscode/settings.json:
{
"rubyLsp.enabledFeatures": {
"completion": false
}
}This disables autocomplete but keeps other features like diagnostics, hover, and go-to-definition working.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingneeds-more-infoMore information is needed to address this issueMore information is needed to address this issue