mirror of https://github.com/docker/cli.git
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. Co-authored-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
parent
cb1def79e5
commit
d5f564adaa
|
@ -163,9 +163,8 @@ func (c *commandConn) Read(p []byte) (int, error) {
|
|||
// Close might get called
|
||||
if c.closing.Load() {
|
||||
// If we're currently closing the connection
|
||||
// we don't want to call onEOF, but we do want
|
||||
// to return an io.EOF
|
||||
return 0, io.EOF
|
||||
// we don't want to call onEOF
|
||||
return n, err
|
||||
}
|
||||
|
||||
return n, c.handleEOF(err)
|
||||
|
@ -178,9 +177,8 @@ func (c *commandConn) Write(p []byte) (int, error) {
|
|||
// Close might get called
|
||||
if c.closing.Load() {
|
||||
// If we're currently closing the connection
|
||||
// we don't want to call onEOF, but we do want
|
||||
// to return an io.EOF
|
||||
return 0, io.EOF
|
||||
// we don't want to call onEOF
|
||||
return n, err
|
||||
}
|
||||
|
||||
return n, c.handleEOF(err)
|
||||
|
|
|
@ -5,6 +5,7 @@ package commandconn
|
|||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/fs"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -178,7 +179,8 @@ func TestCloseWhileWriting(t *testing.T) {
|
|||
assert.Check(t, !process.Alive(cmdConn.cmd.Process.Pid))
|
||||
|
||||
writeErr := <-writeErrC
|
||||
assert.ErrorContains(t, writeErr, "EOF")
|
||||
assert.ErrorContains(t, writeErr, "file already closed")
|
||||
assert.Check(t, is.ErrorIs(writeErr, fs.ErrClosed))
|
||||
}
|
||||
|
||||
func TestCloseWhileReading(t *testing.T) {
|
||||
|
@ -208,5 +210,5 @@ func TestCloseWhileReading(t *testing.T) {
|
|||
assert.Check(t, !process.Alive(cmdConn.cmd.Process.Pid))
|
||||
|
||||
readErr := <-readErrC
|
||||
assert.ErrorContains(t, readErr, "EOF")
|
||||
assert.Check(t, is.ErrorIs(readErr, fs.ErrClosed))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue