Repository navigation
Serialize Jedi language server restarts and clean up in-flight starts (fixes #26296) - #26300
Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Conversation
…fixes microsoft#26296) When changing interpreters and restarting the Jedi language server in quick succession, overlapping start/stop calls can leave orphan run-jedi-language-server.py processes running. Additionally, restarting before the server has finished its initial start spawns an unconnected server, and python.analysis.restartLanguageServer failed to return its restart promise. This change: 1. Returns the restart promise from the python.analysis.restartLanguageServer command. 2. Tracks started state and safely no-ops if restart is triggered before initial start. 3. Serializes overlapping restart calls sequentially through an execution queue. 4. Cleans up and kills in-flight language client processes if stop() is called while start() is awaiting client creation/startup in JediLanguageServerProxy. 5. Adds unit tests covering command return value, serialization, and proxy in-flight stop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #26296
When switching interpreters in quick succession or triggering
python.analysis.restartLanguageServerwhile an interpreter change or previous restart is still in progress, overlappingstart()andstop()invocations can result in orphanedrun-jedi-language-server.pyprocesses running in the background. Furthermore, runningpython.analysis.restartLanguageServerbefore Jedi has finished initial start starts an unconnected server that causes completion to hang, and the command handler did not return the restart promise.Root Cause
JediLanguageServerProxy.start()creates and starts aLanguageClientasynchronously. Ifstop()is called whilecreateLanguageClient()orclient.start()is in-flight,this.languageClientis stillundefined, causingstop()to do nothing. Onceclient.start()resolves,this.languageClient = clientis set, leaving the process running and untracked.JediLanguageServerManagerdid not serializerestartLanguageServer()calls, allowing multiple restarts to interleave.JediLanguageServerManagerhad no check for whether the initialstart()completed before restarting, allowing uninitialized/unconnected starts.commandManager.registerCommand(Commands.RestartLS, ...)executedrestartLanguageServer()without returning the promise.Solution
isStoppedandstartingClientinJediLanguageServerProxy. Ifstop()is invoked while client creation or startup is awaiting,isStoppedensures the newly started client is immediately stopped, disposed, and its PID terminated.restartQueue) inJediLanguageServerManager.restartLanguageServer()so overlapping restarts wait for each other.startedinJediLanguageServerManagerand no-oprestartLanguageServer()if initial start has not completed.this.restartLanguageServer()from theCommands.RestartLScommand handler so callers canawaitthe restart completion.Verification
npx tsc -p ./: Passed with 0 errors.npx eslint src/client/activation/jedi/manager.ts src/client/activation/jedi/languageServerProxy.ts src/test/activation/jedi/jediLanguageServerManager.unit.test.ts: 0 errors.npx mocha -r out/test/unittests.js --ui tdd out/test/activation/jedi/jediLanguageServerManager.unit.test.js out/test/languageServer/jediLSExtensionManager.unit.test.js out/test/activation/jedi/jediAnalysisOptions.unit.test.js): 11/11 tests passed.