Skip to content

Shutdown handler drops responses and violates LSP state machine #605

@meymchen

Description

@meymchen

Component

pygls/protocol/json_rpc.py

Summary

After receiving the shutdown request, _shutdown is set to True and handle_message rejects every subsequent message except exit. This includes responses from the client to requests that the server sent before shutdown (e.g., client/registerCapability, workspace/configuration). Per the LSP specification, the server must not exit until exit is received, and in-flight bidirectional communication must still be honored.

Steps to Reproduce

  1. Server sends a request to the client (e.g., workspace/configuration).
  2. Client sends shutdown before responding.
  3. The server drops the client's response because _shutdown blocks it.
  4. The internal Future associated with the request leaks and never resolves.

Expected Behavior

_handle_response should continue processing even after shutdown. Only new client requests/notifications (other than exit) should be ignored.

Actual Behavior

All messages except exit are dropped after shutdown.

Affected Code (pygls/protocol/json_rpc.py, ~L496-498)

if self._shutdown and getattr(message, "method", "") != EXIT:
    logger.warning("Server shutting down. No more requests!")
    return

Proposed Fix

Guard _handle_request and _handle_notification, but allow _handle_response to pass through regardless of the _shutdown flag.

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