From 1983f37f63c8082441bfed83f8c18047e20217e4 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Thu, 9 Sep 2021 16:50:42 -0500 Subject: [PATCH] fix: ensure wsep processes are closed --- internal/sync/singlefile.go | 1 + internal/sync/sync.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/internal/sync/singlefile.go b/internal/sync/singlefile.go index adf8c290..72d7a2a0 100644 --- a/internal/sync/singlefile.go +++ b/internal/sync/singlefile.go @@ -39,6 +39,7 @@ func SingleFile(ctx context.Context, local, remoteDir string, workspace *coder.W if err != nil { return xerrors.Errorf("start sync command: %w", err) } + defer process.Close() sourceFile, err := os.Open(local) if err != nil { diff --git a/internal/sync/sync.go b/internal/sync/sync.go index dd90cf7a..bceead68 100644 --- a/internal/sync/sync.go +++ b/internal/sync/sync.go @@ -109,6 +109,8 @@ func (s Sync) remoteCmd(ctx context.Context, prog string, args ...string) error if err != nil { return xerrors.Errorf("exec remote process: %w", err) } + defer process.Close() + // NOTE: If the copy routine fail, it will result in `process.Wait` to unblock and report an error. go func() { _, _ = io.Copy(s.OutW, process.Stdout()) }() // Best effort. go func() { _, _ = io.Copy(s.ErrW, process.Stderr()) }() // Best effort. @@ -290,6 +292,8 @@ func (s Sync) Version() (string, error) { if err != nil { return "", err } + defer process.Close() + buf := &bytes.Buffer{} _, _ = io.Copy(buf, process.Stdout()) // Ignore error, if any, it would be handled by the process.Wait return.