container: normalize closed CRI pipe read errors

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-08 22:45:33 +02:00
parent 864088b034
commit eb2c7165c7
2 changed files with 14 additions and 0 deletions
+9
View File
@@ -159,6 +159,15 @@ func (c *pipeConn) Read(p []byte) (int, error) {
}
})
if err != nil {
// Control can reject a closed file before invoking the callback.
c.mu.Lock()
closed := c.closed
c.mu.Unlock()
if closed {
err = os.ErrClosed
}
return 0, err
}
@@ -280,6 +280,11 @@ func TestPipeConnClose(t *testing.T) {
case <-time.After(5 * time.Second):
t.Fatal("Close did not release the pipe handle")
}
// A read started after Close must return the same error as a canceled read.
n, err := server.Read(make([]byte, 1))
require.Zero(t, n)
require.ErrorIs(t, err, os.ErrClosed)
}
// Both peers write first. On a pipe without buffer, this blocks both writes