Skip to content

Ensure LSP readLoop doesn't block shutdown #1074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025
Merged

Conversation

jakebailey
Copy link
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.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch
@jakebailey jakebailey requested review from gabritto and Copilot June 5, 2025 23:12
@jakebailey jakebailey mentioned this pull request Jun 5, 2025
Copy link
Contributor

@Copilot 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 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 {

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch
return err
}
})
go func() { readLoopErr <- s.readLoop(ctx) }()
Copy link
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 jakebailey enabled auto-merge June 5, 2025 23:22
@jakebailey jakebailey added this pull request to the merge queue Jun 5, 2025
Merged via the queue into main with commit 3af9097 Jun 5, 2025
23 checks passed
@jakebailey jakebailey deleted the jabaile/server-exit branch June 5, 2025 23:49
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.

None yet

2 participants