Commit 900f2dc9 authored by Alessio Caiazza's avatar Alessio Caiazza

Check waitDone channel only in case of os.PathError

parent 979ae9aa
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"os"
"os/exec" "os/exec"
"regexp" "regexp"
...@@ -37,10 +38,6 @@ func NewCleaner(ctx context.Context, stdin io.Reader) (io.Reader, error) { ...@@ -37,10 +38,6 @@ func NewCleaner(ctx context.Context, stdin io.Reader) (io.Reader, error) {
} }
func (c *cleaner) Read(p []byte) (int, error) { func (c *cleaner) Read(p []byte) (int, error) {
select {
case <-c.waitDone:
return 0, io.EOF
default:
n, err := c.stdout.Read(p) n, err := c.stdout.Read(p)
if err == io.EOF { if err == io.EOF {
if waitErr := c.wait(); waitErr != nil { if waitErr := c.wait(); waitErr != nil {
...@@ -53,8 +50,18 @@ func (c *cleaner) Read(p []byte) (int, error) { ...@@ -53,8 +50,18 @@ func (c *cleaner) Read(p []byte) (int, error) {
} }
} }
// Calling c.cmd.Wait() will close the stdout pipe, any attempt to read from it will fail with an os.PathError.
// see: https://gitlab.com/gitlab-org/gitlab-workhorse/-/issues/233
if _, ok := err.(*os.PathError); ok {
select {
case <-c.waitDone:
return n, io.EOF
default:
return n, err return n, err
} }
}
return n, err
} }
func (c *cleaner) startProcessing(stdin io.Reader) error { func (c *cleaner) startProcessing(stdin io.Reader) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment