Skip to content

Commit 5cd83f3

Browse files
darfuxfuweid
authored andcommitted
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]> (cherry picked from commit cf6e008) Signed-off-by: Wei Fu <[email protected]>
1 parent 0717fe6 commit 5cd83f3

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
@@ -329,7 +329,7 @@ func TestShimDoesNotLeakPipes(t *testing.T) {
329329
}
330330

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

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

runtime/v1/shim/client/client.go

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

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)