Skip to content
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

cmd/govim: do not wait more than 500ms for gopls Shutdown #1075

Merged
merged 1 commit into from
Apr 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions cmd/govim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"context"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -394,14 +395,19 @@ func (g *govimplugin) Shutdown() error {
}
os.RemoveAll(g.socketDir) // see note above

// Shutdown gopls
//
// We "kill" gopls by closing its stdin. Standard practice for processes
// that communicate over stdin/stdout is to exit cleanly when stdin is
// closed.
if err := g.server.Shutdown(context.Background()); err != nil {
// TODO: remove this workaround for golang.org/issue/45476. We should not
// have to set a deadline for our call to Shutdown. 500ms is the longest a
// user should be expected to wait before "forcing" the shutdown sequence.
// Because of golang.org/issue/45476, the shorter we make this timeout the
// greater the likelihood that gopls will leave $TMPDIR artefacts lying
// around, and not have properly tidied up after itself.
ctxt, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
if err := g.server.Shutdown(ctxt); err != nil && !errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("failed to call gopls Shutdown: %v", err)
}
// As the initiator of the connection to gopls, complete shutdown by closing
// stdin to the process we started.
if err := g.goplsStdin.Close(); err != nil {
return fmt.Errorf("failed to close gopls stdin: %v", err)
}
Expand Down