Skip to content

Commit cf6e008

Browse files
committed
Fix fd leak of shim log
Open shim v2 log with the flag `O_RDWR` will cause the `Read()` block forever even if the pipe has been closed on the shim side. Then the `io.Copy()` would never return and lead to a fd leak. Fix typo when closing shim v1 log which causes the `stdouLog` leak. Update `numPipes` function in test case to get the opened FIFO correctly. Signed-off-by: Li Yuxuan <[email protected]>
1 parent d68b593 commit cf6e008

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

container_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func TestShimDoesNotLeakPipes(t *testing.T) {
330330
}
331331

332332
func numPipes(pid int) (int, error) {
333-
cmd := exec.Command("sh", "-c", fmt.Sprintf("lsof -p %d | grep pipe", pid))
333+
cmd := exec.Command("sh", "-c", fmt.Sprintf("lsof -p %d | grep FIFO", pid))
334334

335335
var stdout bytes.Buffer
336336
cmd.Stdout = &stdout

runtime/v1/shim/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
9898
cmd.Wait()
9999
exitHandler()
100100
if stdoutLog != nil {
101-
stderrLog.Close()
101+
stdoutLog.Close()
102102
}
103-
if stdoutLog != nil {
103+
if stderrLog != nil {
104104
stderrLog.Close()
105105
}
106106
}()

runtime/v2/shim_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ import (
2828
)
2929

3030
func openShimLog(ctx context.Context, bundle *Bundle) (io.ReadCloser, error) {
31-
return fifo.OpenFifo(ctx, filepath.Join(bundle.Path, "log"), unix.O_RDWR|unix.O_CREAT, 0700)
31+
return fifo.OpenFifo(ctx, filepath.Join(bundle.Path, "log"), unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
3232
}

0 commit comments

Comments
 (0)