Skip to content

Commit e1a6adc

Browse files
kolyshkinlifubang
authored andcommitted
libct/int: TestFdLeaks: deflake
Since the recent CVE fixes, TestFdLeaksSystemd sometimes fails: === RUN TestFdLeaksSystemd exec_test.go:1750: extra fd 9 -> /12224/task/13831/fd exec_test.go:1753: found 1 extra fds after container.Run --- FAIL: TestFdLeaksSystemd (0.10s) It might have been caused by the change to the test code in commit ff6fe13 ("utils: use safe procfs for /proc/self/fd loop code") -- we are now opening a file descriptor during the logic to get a list of file descriptors. If the file descriptor happens to be allocated to a different number, you'll get an error. Let's try to filter out the fd used to read a directory. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> (cherry picked from commit 5fbc3bb) Signed-off-by: lifubang <lifubang@acmcoder.com>
1 parent cef8c32 commit e1a6adc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libcontainer/integration/exec_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os/exec"
1010
"path/filepath"
1111
"reflect"
12+
"slices"
1213
"strconv"
1314
"strings"
1415
"syscall"
@@ -1702,7 +1703,11 @@ func fdList(t *testing.T) []string {
17021703
fds, err := fdDir.Readdirnames(-1)
17031704
ok(t, err)
17041705

1705-
return fds
1706+
// Remove the fdDir fd.
1707+
extraFd := strconv.Itoa(int(fdDir.Fd()))
1708+
return slices.DeleteFunc(fds, func(fd string) bool {
1709+
return fd == extraFd
1710+
})
17061711
}
17071712

17081713
func testFdLeaks(t *testing.T, systemd bool) {
@@ -1724,7 +1729,7 @@ func testFdLeaks(t *testing.T, systemd bool) {
17241729
_ = runContainerOk(t, config, "true")
17251730
fds1 := fdList(t)
17261731

1727-
if reflect.DeepEqual(fds0, fds1) {
1732+
if slices.Equal(fds0, fds1) {
17281733
return
17291734
}
17301735
// Show the extra opened files.

0 commit comments

Comments
 (0)