Skip to content

Treat connection close during stop() as handled - #1782

Open
Lionel Henry (lionel-) wants to merge 4 commits into
microsoft:mainfrom
lionel-:bugfix/lsp-close-race
Open

Lionel Henry (lionel-) wants to merge 4 commits into
microsoft:mainfrom
lionel-:bugfix/lsp-close-race

Conversation

@lionel-

Copy link
Copy Markdown

We've hit a case where our closed() handler, meant to prevent user-visible toast notifications, was not invoked by languageclient. Our Linux users (likely due to some weird platform-specific race) consistently see a toast notification on restart due to this (posit-dev/positron#7593).

I think this is because the closed() handler is not called when the client is already stopping: https://github.com/lionel-/vscode-languageserver-node/blob/f5e23e29b76c42fad882aa84933d46ba9b412183/client/src/common/client.ts#L1827-L1833. This prevents our handler from setting handled to true.

The fix proposed here is to treat a client that's already stopping as "handled", this way a toast notification isn't displayed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The notification regression needs automated test coverage.

1 open finding
What changed in this PR

Suppresses user-visible connection-close notifications when closure occurs during stop().

Changes:

  • Treats the Stopping state as handled.
  • Retains output-channel logging without showing a toast.
File Description
client/​src/​common/​client.ts Handles connection closure during shutdown without notification.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

this._connection = undefined;
// `Stopping` counts as handled. The application asked for the close via `stop()`,
// and `closed()` was skipped above so the handler had no chance to set `handled`.
const handled = this.$state === ClientState.Stopping || handlerResult.handled === true;

@dbaeumer Dirk Bäumer (dbaeumer) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See the Copilot review comment.

@lionel-

Copy link
Copy Markdown
Author

Dirk Bäumer (@dbaeumer) I've added a test

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused state-handling change is correct and covered by an appropriate integration test.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized change preserves existing behavior outside shutdown and includes focused regression coverage, with no blocking issues identified.

1 open issue

Review effort: Balanced

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.

4 participants