Skip to content

Server exits on shutdown instead of waiting for the exit notification #862

Open

Description

@eitsupi

This issue is based on an analysis by Claude and Codex (AI coding agents).

on_shutdown() sets self$exit_flag <- TRUE before sending its response (R/handlers-general.R), and the main loop in run() exits as soon as it sees the flag (R/languageserver.R). So the server terminates right after answering shutdown, without waiting for the exit notification.

The LSP specification says that shutdown asks the server to shut down without exiting, and that the server exits on the subsequent exit notification.

Clients such as vscode-languageclient send exit after the shutdown response arrives. Because the server may already have closed the connection, writing exit can fail (EPIPE on macOS/Linux, ECONNABORTED/ECONNRESET on Windows). In vscode-R, this made stopping a server fail and, on Windows, showed users a "connection to server is erroring" notification. vscode-R is working around it on the client side (REditorSupport/vscode-R#1955).

Suggested fix: in on_shutdown(), do the cleanup and reply, but leave exit_flag unset, so that the server keeps reading until on_exit() sets the flag.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions