Skip to content

Commit ee888c6

Browse files
committed
commandconn: return original error while closing
Changes the `Read` and `Write` error handling logic to return the original error while closing the connection. We still skip calling `handleEOF` if already closing the connection. Fixes the flaky `TestCloseWhileWriting` and `TestCloseWhileReading` tests. Signed-off-by: Laura Brehm <[email protected]>
1 parent cb1def7 commit ee888c6

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestCloseWhileWriting(t *testing.T) {
178178
assert.Check(t, !process.Alive(cmdConn.cmd.Process.Pid))
179179

180180
writeErr := <-writeErrC
181-
assert.ErrorContains(t, writeErr, "EOF")
181+
assert.ErrorContains(t, writeErr, "file already closed")
182182
}
183183

184184
func TestCloseWhileReading(t *testing.T) {
@@ -208,5 +208,5 @@ func TestCloseWhileReading(t *testing.T) {
208208
assert.Check(t, !process.Alive(cmdConn.cmd.Process.Pid))
209209

210210
readErr := <-readErrC
211-
assert.ErrorContains(t, readErr, "EOF")
211+
assert.ErrorContains(t, readErr, "file already closed")
212212
}

0 commit comments

Comments
 (0)