Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

fix: ensure wsep processes are closed #436

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions internal/sync/singlefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down