Skip to content

Conversation

@andrewbranch
Copy link
Member

In #2499, we started checking for context cancelation during sending responses as a way to ensure we don’t get stuck trying to write a message to a client that has exited. If the context is canceled, we would bail out returning an error, but that error would eventually be ignored. Ignoring the error is a problem, but the big problem was that we were checking the request context during sending. If the request was canceled, we would try to send an error response saying the request was canceled, but we would fail to send it since the context was canceled. This left the client perpetually waiting for our response and never asking for new errors.

Fixes #2557

Copilot AI review requested due to automatic review settings January 22, 2026 18:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical issue where the language server would fail to send error responses when requests were canceled, leaving clients waiting indefinitely. The fix separates the context used for request processing from the context used for sending responses.

Changes:

  • Removed context parameters from all send-related functions (send, sendResult, sendError, sendResponse), using the server's backgroundCtx instead to ensure responses can be sent even when individual requests are canceled
  • Improved error handling by checking and propagating errors from send operations rather than ignoring them, with failed sends triggering server shutdown via lspExit
  • Enhanced context management by switching to WithCancelCause for better error tracking

@andrewbranch andrewbranch added this pull request to the merge queue Jan 22, 2026
Merged via the queue into microsoft:main with commit dd158be Jan 22, 2026
27 checks passed
@andrewbranch andrewbranch deleted the bug/2557 branch January 22, 2026 18:42
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.

Suggestions freeze and stop working until I close and open the file again

2 participants