Skip to content

Let language server subprocess be its own process group #77

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

Merged
merged 2 commits into from
Mar 8, 2025

Conversation

jetzhou
Copy link
Contributor

@jetzhou jetzhou commented Mar 5, 2025

In situations where multilspy is launched from another process, a SIGINT or SIGTERM signal will be received by both the launching process as well as the process running the language server because asyncio.create_subprocess_shell defaults to start_new_session=False. In such a situation, lsp_protocol_handler.server.shutdown will be called but will hang since the underlying process is already terminated, lsp_protocol_handler.server won't ever receive an answer back for shutdown.

This change makes it so that SIGINT and SIGTERM won't propagate to the language server process. We rely on the clean up code already in place to shut down the process as desired.

See python documentation for more details on start_new_session

In situations where `multilspy` is launched from another process, a
SIGINT or SIGTERM signal will be received by both the launching process
as well as the process running the language server because
`asyncio.create_subprocess_shell` defaults to `start_new_session=False`.
In such a situation, `lsp_protocol_handler.server.shutdown` will be
called but will hang since the underlying process is already terminated,
`lsp_protocol_handler.server` won't ever receive an answer back for
`shutdown`.

This change makes it so that SIGINT and SIGTERM won't propagate to the
language server process. We rely on the clean up code already in place
to shut down the process as desired.

See
[python documentation](https://docs.python.org/3.13/library/subprocess.html#subprocess.Popen)
for more details on `start_new_session`
@LakshyAAAgrawal
Copy link
Collaborator

Nice catch! Thanks for the PR. Can we make this configurable? Just add a flag to MultilspyConfig, and set it to true by defualt.

…yConfig`

Default value is `True`, which means language server process will be in
its own process group. SIGINT and SIGTERM will only be received by the
`multilspy` python process itself, not propagated. We rely on the
existing `shutdown` and `stop` code to clean up the process.

If set to `False`, the language server process will be under the same
process group as the `multilspy` python process. This means SIGINT and
SIGTERM will be received by both processes. This may cause issues if the
python process has clean up code that runs after receiving
SIGINT/SIGTERM because the `start_server` context manager will begin
running its cleanup code, part of which invokes the `shutdown` and
`stop` in `language_protocol_handler.server`. This will hang forever
while awaiting an response from the language server process, since it
would have already terminated itself after receiving SIGINT/SIGTERM.
@jetzhou
Copy link
Contributor Author

jetzhou commented Mar 7, 2025

Definitely! Updated the PR to use start_independent_lsp_process in config to control this behavior.

@LakshyAAAgrawal LakshyAAAgrawal merged commit a4323aa into microsoft:main Mar 8, 2025
4 checks passed
@jetzhou jetzhou deleted the start-new-session branch March 10, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants