container: normalize closed CRI pipe read errors (#2560)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-08 23:11:10 +02:00
committed by GitHub
parent 864088b034
commit 64559e8f76
2 changed files with 87 additions and 1 deletions
+20 -1
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
}
@@ -200,6 +209,8 @@ func (c *pipeConn) SetDeadline(t time.Time) error { return c.SetWriteDeadline(t)
type readAheadConn struct {
net.Conn
readWG sync.WaitGroup
mu sync.Mutex
cond *sync.Cond
buf []byte
@@ -210,7 +221,7 @@ func newReadAheadConn(conn net.Conn) *readAheadConn {
c := &readAheadConn{Conn: conn}
c.cond = sync.NewCond(&c.mu)
go c.readLoop()
c.readWG.Go(c.readLoop)
return c
}
@@ -255,6 +266,14 @@ func (c *readAheadConn) Read(p []byte) (int, error) {
return n, nil
}
// Close cancels the read and waits for the background reader to exit.
func (c *readAheadConn) Close() error {
err := c.Conn.Close()
c.readWG.Wait()
return err
}
// SetDeadline only applies to writes. A read deadline would stop the background reader for good.
func (c *readAheadConn) SetDeadline(t time.Time) error {
return c.SetWriteDeadline(t)