From e2bdc7ac8c1f665bec2a1b64c4ace02fae3192a8 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Thu, 31 Aug 2023 12:03:12 -0700 Subject: [PATCH] Update termtest to address potential premature close issue --- go.mod | 2 +- go.sum | 4 ++-- .../github.com/ActiveState/termtest/outputproducer.go | 11 +++++++---- vendor/modules.txt | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 212fff7588..b860e016bb 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ replace cloud.google.com/go => cloud.google.com/go v0.110.0 require ( github.com/99designs/gqlgen v0.17.19 github.com/ActiveState/go-ogle-analytics v0.0.0-20170510030904-9b3f14901527 - github.com/ActiveState/termtest v0.7.3-0.20230830215505-502ea17ca523 + github.com/ActiveState/termtest v0.7.3-0.20230831190140-b647873f765e github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 github.com/andygrunwald/go-jira v1.15.1 diff --git a/go.sum b/go.sum index 04fc6c74c2..79d0086208 100644 --- a/go.sum +++ b/go.sum @@ -345,8 +345,8 @@ github.com/ActiveState/graphql v0.0.0-20230719154233-6949037a6e48 h1:UCx/ObpVRgC github.com/ActiveState/graphql v0.0.0-20230719154233-6949037a6e48/go.mod h1:NhUbNQ8UpfnC6nZvZ8oThqYSCE/G8FQp9JUrK9jXJs0= github.com/ActiveState/pty v0.0.0-20230628221854-6fb90eb08a14 h1:RdhhSiwmgyUaaF2GBNrbqTwE5SM+MaVjwf91Ua+CK8c= github.com/ActiveState/pty v0.0.0-20230628221854-6fb90eb08a14/go.mod h1:5mM6vNRQwshCjlkOnVpwC//4ZpkiC6nmZr8lPOxJdXs= -github.com/ActiveState/termtest v0.7.3-0.20230830215505-502ea17ca523 h1:nDbSj//mvn7DSGU/ChMaXT8GV8G8cMRYjY+ZpuO7ylo= -github.com/ActiveState/termtest v0.7.3-0.20230830215505-502ea17ca523/go.mod h1:7VnCvgQKKktm2gZ+MlL1vZGi1k4lR97iABpTGqWAvnc= +github.com/ActiveState/termtest v0.7.3-0.20230831190140-b647873f765e h1:DMlPdYgNWvMt1A9+1vEA7CyfjmcXJwZpjE1pXBgr9mg= +github.com/ActiveState/termtest v0.7.3-0.20230831190140-b647873f765e/go.mod h1:7VnCvgQKKktm2gZ+MlL1vZGi1k4lR97iABpTGqWAvnc= github.com/AlecAivazis/survey/v2 v2.0.5/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= diff --git a/vendor/github.com/ActiveState/termtest/outputproducer.go b/vendor/github.com/ActiveState/termtest/outputproducer.go index ce10fb277f..9cf19946b2 100644 --- a/vendor/github.com/ActiveState/termtest/outputproducer.go +++ b/vendor/github.com/ActiveState/termtest/outputproducer.go @@ -55,8 +55,7 @@ func (o *outputProducer) listen(r io.Reader, w io.Writer, appendBuffer func([]by for { o.opts.Logger.Println("listen: loop") if err := o.processNextRead(br, w, appendBuffer, size); err != nil { - pathError := &fs.PathError{} - if errors.Is(err, fs.ErrClosed) || errors.Is(err, io.EOF) || (runtime.GOOS == "linux" && errors.As(err, &pathError)) { + if errors.Is(err, ptyEOF) { o.opts.Logger.Println("listen: reached EOF") return nil } else { @@ -66,6 +65,8 @@ func (o *outputProducer) listen(r io.Reader, w io.Writer, appendBuffer func([]by } } +var ptyEOF = errors.New("pty closed") + func (o *outputProducer) processNextRead(r io.Reader, w io.Writer, appendBuffer func([]byte) error, size int) error { o.opts.Logger.Printf("processNextRead started with size: %d\n", size) defer o.opts.Logger.Println("processNextRead stopped") @@ -83,9 +84,11 @@ func (o *outputProducer) processNextRead(r io.Reader, w io.Writer, appendBuffer } } - // Error doesn't necessarily mean something went wrong, we may just have reached the natural end - // It's the consumers job to check for EOF errors and ignore them if they're expected if errRead != nil { + pathError := &fs.PathError{} + if errors.Is(errRead, fs.ErrClosed) || errors.Is(errRead, io.EOF) || (runtime.GOOS == "linux" && errors.As(errRead, &pathError)) { + return errors.Join(errRead, ptyEOF) + } return fmt.Errorf("could not read pty output: %w", errRead) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 2c7872229c..3d1ae4e888 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -19,7 +19,7 @@ github.com/ActiveState/graphql # github.com/ActiveState/pty v0.0.0-20230628221854-6fb90eb08a14 ## explicit; go 1.13 github.com/ActiveState/pty -# github.com/ActiveState/termtest v0.7.3-0.20230830215505-502ea17ca523 +# github.com/ActiveState/termtest v0.7.3-0.20230831190140-b647873f765e ## explicit; go 1.18 github.com/ActiveState/termtest # github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78