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 <liyuxuan04@baidu.com>
This commit is contained in:
parent
d68b593de4
commit
cf6e008542
@ -330,7 +330,7 @@ func TestShimDoesNotLeakPipes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func numPipes(pid int) (int, error) {
|
func numPipes(pid int) (int, error) {
|
||||||
cmd := exec.Command("sh", "-c", fmt.Sprintf("lsof -p %d | grep pipe", pid))
|
cmd := exec.Command("sh", "-c", fmt.Sprintf("lsof -p %d | grep FIFO", pid))
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
|
@ -98,9 +98,9 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
|
|||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
exitHandler()
|
exitHandler()
|
||||||
if stdoutLog != nil {
|
if stdoutLog != nil {
|
||||||
stderrLog.Close()
|
stdoutLog.Close()
|
||||||
}
|
}
|
||||||
if stdoutLog != nil {
|
if stderrLog != nil {
|
||||||
stderrLog.Close()
|
stderrLog.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -28,5 +28,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func openShimLog(ctx context.Context, bundle *Bundle) (io.ReadCloser, error) {
|
func openShimLog(ctx context.Context, bundle *Bundle) (io.ReadCloser, error) {
|
||||||
return fifo.OpenFifo(ctx, filepath.Join(bundle.Path, "log"), unix.O_RDWR|unix.O_CREAT, 0700)
|
return fifo.OpenFifo(ctx, filepath.Join(bundle.Path, "log"), unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user