Skip to content

Commit dc2eb3b

Browse files
authored
Merge pull request #4394 from laurazard/fix-flaky-ssh
commandconn: return original error while closing
2 parents e413dae + d5f564a commit dc2eb3b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cli/connhelper/commandconn/commandconn.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ func (c *commandConn) Read(p []byte) (int, error) {
163163
// Close might get called
164164
if c.closing.Load() {
165165
// If we're currently closing the connection
166-
// we don't want to call onEOF, but we do want
167-
// to return an io.EOF
168-
return 0, io.EOF
166+
// we don't want to call onEOF
167+
return n, err
169168
}
170169

171170
return n, c.handleEOF(err)
@@ -178,9 +177,8 @@ func (c *commandConn) Write(p []byte) (int, error) {
178177
// Close might get called
179178
if c.closing.Load() {
180179
// If we're currently closing the connection
181-
// we don't want to call onEOF, but we do want
182-
// to return an io.EOF
183-
return 0, io.EOF
180+
// we don't want to call onEOF
181+
return n, err
184182
}
185183

186184
return n, c.handleEOF(err)

cli/connhelper/commandconn/commandconn_unix_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package commandconn
55
import (
66
"context"
77
"io"
8+
"io/fs"
89
"testing"
910
"time"
1011

@@ -178,7 +179,8 @@ func TestCloseWhileWriting(t *testing.T) {
178179
assert.Check(t, !process.Alive(cmdConn.cmd.Process.Pid))
179180

180181
writeErr := <-writeErrC
181-
assert.ErrorContains(t, writeErr, "EOF")
182+
assert.ErrorContains(t, writeErr, "file already closed")
183+
assert.Check(t, is.ErrorIs(writeErr, fs.ErrClosed))
182184
}
183185

184186
func TestCloseWhileReading(t *testing.T) {
@@ -208,5 +210,5 @@ func TestCloseWhileReading(t *testing.T) {
208210
assert.Check(t, !process.Alive(cmdConn.cmd.Process.Pid))
209211

210212
readErr := <-readErrC
211-
assert.ErrorContains(t, readErr, "EOF")
213+
assert.Check(t, is.ErrorIs(readErr, fs.ErrClosed))
212214
}

0 commit comments

Comments
 (0)