1
0
mirror of https://github.com/golang/go synced 2024-11-05 11:36:10 -07:00

internal/jsonrpc2,internal/lsp/regtest: clean up some leaked tempfiles

Not all regtests resulted in LSP shutdown, which caused temp modfiles to
be leaked. After this fix I have confirmed that /tmp is clean after a
successful run of the regtests.

Also proactively clean up the unix socket file when serving jsonrpc2
over UDS.

Change-Id: I745fbd3d2adeeb165cadf7c54fd815d8df81d4e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220061
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rob Findley 2020-02-18 20:53:06 -05:00 committed by Robert Findley
parent 5fb17a1e7b
commit 66de428735
3 changed files with 22 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import (
"context"
"log"
"net"
"os"
)
// NOTE: This file provides an experimental API for serving multiple remote
@ -47,6 +48,9 @@ func ListenAndServe(ctx context.Context, network, addr string, server StreamServ
if err != nil {
return err
}
if network == "unix" {
defer os.Remove(addr)
}
return Serve(ctx, ln, server)
}

View File

@ -70,12 +70,19 @@ func NewEditor(ws *Workspace) *Editor {
}
}
// ShutdownAndExit shuts down the client and issues the editor exit.
func (e *Editor) ShutdownAndExit(ctx context.Context) error {
// Shutdown issues the 'shutdown' LSP notification.
func (e *Editor) Shutdown(ctx context.Context) error {
if e.server != nil {
if err := e.server.Shutdown(ctx); err != nil {
return fmt.Errorf("Shutdown: %v", err)
}
}
return nil
}
// Exit issues the 'exit' LSP notification.
func (e *Editor) Exit(ctx context.Context) error {
if e.server != nil {
// Not all LSP clients issue the exit RPC, but we do so here to ensure that
// we gracefully handle it on multi-session servers.
if err := e.server.Exit(ctx); err != nil {

View File

@ -173,6 +173,11 @@ func (r *Runner) RunInMode(modes EnvMode, t *testing.T, filedata string, test fu
ts, cleanup := tc.getConnector(ctx, t)
defer cleanup()
env := NewEnv(ctx, t, ws, ts)
defer func() {
if err := env.E.Shutdown(ctx); err != nil {
panic(err)
}
}()
test(ctx, t, env)
})
}
@ -326,7 +331,10 @@ func (e *Env) onDiagnostics(_ context.Context, d *protocol.PublishDiagnosticsPar
// CloseEditor shuts down the editor, calling t.Fatal on any error.
func (e *Env) CloseEditor() {
e.t.Helper()
if err := e.E.ShutdownAndExit(e.ctx); err != nil {
if err := e.E.Shutdown(e.ctx); err != nil {
e.t.Fatal(err)
}
if err := e.E.Exit(e.ctx); err != nil {
e.t.Fatal(err)
}
}