mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-17 01:59:04 +02:00
container: normalize closed CRI pipe read errors
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user