Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Ensure LSP readLoop doesn't block shutdown - #1074

Merged
Jake Bailey (jakebailey) merged 2 commits into
mainfrom
jabaile/server-exit
Jun 5, 2025
Merged

Jake Bailey (jakebailey) merged 2 commits into
mainfrom
jabaile/server-exit

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Sort of pulled out of #991, but I'm hoping this helps people who are seeing their tsgo processes not exit.

The next measure we could take is to watch the parent process (PID is given during init) and exit if it exits.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR prevents the readLoop from blocking process shutdown by running it in a standalone goroutine and tweaks the error check on g.Wait().

  • Extract readLoop out of the error group so it’s not tied to the group’s cancellation.
  • Spawn readLoop in a fire-and-forget goroutine and suppress its error.
  • Refine the g.Wait() error condition to also check ctx.Err().
Comments suppressed due to low confidence (1)

internal/lsp/server.go:201

  • Requiring ctx.Err() != nil in the error check may suppress genuine errors from dispatchLoop or writeLoop when the context hasn't been cancelled. Consider reverting to the original condition (err != nil && !errors.Is(err, io.EOF)) to ensure you don’t miss critical failures.
if err := g.Wait(); err != nil && !errors.Is(err, io.EOF) && ctx.Err() != nil {

Comment thread internal/lsp/server.go Resolved
Comment thread internal/lsp/server.go
return err
}
})
go func() { readLoopErr <- s.readLoop(ctx) }()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This goroutine can leak if the reader never exits, but I'm trying to handle the case where the process is exiting due to a cancellation cancel via a signal, so, it's hard to do better here without cancelable stdin reads ☹️

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Jun 5, 2025
Merged via the queue into main with commit 3af9097 Jun 5, 2025
@jakebailey
Jake Bailey (jakebailey) deleted the jabaile/server-exit branch June 5, 2025 23:49
Jake Bailey (jakebailey) added a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants