Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language server sometimes crashes when saving a new C# file #7656

Closed
dibarbet opened this issue Oct 11, 2024 · 0 comments · Fixed by dotnet/roslyn#75509
Closed

Language server sometimes crashes when saving a new C# file #7656

dibarbet opened this issue Oct 11, 2024 · 0 comments · Fixed by dotnet/roslyn#75509
Assignees
Milestone

Comments

@dibarbet
Copy link
Member

To repro

  1. Create a new unsaved file and update the language to C# in VSCode
  2. Save the file somewhere in the workspace

At step 2, sometimes the language server will crash with

"message": "[LanguageServerHost] System.InvalidOperationException: Unable to determine language for 'untitled:Untitled-1' with LSP language id ''\r\n   at Microsoft.CodeAnalysis.LanguageServer.LanguageInfoProvider.GetLanguageInformation(Uri uri, String lspLanguageId) in /_/src/LanguageServer/Protocol/LanguageInfoProvider.cs:line 70\r\n   at Microsoft.CodeAnalysis.LanguageServer.RoslynLanguageServer.GetLanguageForRequest(String methodName, Object serializedParameters) in /_/src/LanguageServer/Protocol/RoslynLanguageServer.cs:line 169\r\n   at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue`1.ProcessQueueAsync()"

Looking at the logs from when this happened, before the exception is thrown, we get a didClose for the same document

[Trace - 10:57:38 AM] Sending notification 'textDocument/didClose'.
Params: {
    "textDocument": {
        "uri": "untitled:Untitled-1"
    }
}

Requests for the unsaved document before the didClose succeed. The issue appears to be that sometimes there are requests in flight for the unsaved document that get processed after the didClose is handled by the server. In didClose, we remove the open document state (which maps the document to the language for it) - https://github.com/dotnet/roslyn/blob/main/src/LanguageServer/Protocol/Handler/DocumentChanges/DidCloseHandler.cs#L36. After we've removed the document state we are no longer able to map the URI to a language (it has no extension).

We should likely stop throwing if we cannot find the language, and use a default value (and log a warning). We cannot hold onto the open document state after didClose - we'll just leak documents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant