Skip to content

Commit cf23612

Browse files
committed
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>
1 parent 59a5ff1 commit cf23612

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
@@ -8,6 +8,7 @@ import (
88
"os/exec"
99
"path/filepath"
1010
"reflect"
11+
"slices"
1112
"strconv"
1213
"strings"
1314
"syscall"
@@ -1694,7 +1695,11 @@ func fdList(t *testing.T) []string {
16941695
fds, err := fdDir.Readdirnames(-1)
16951696
ok(t, err)
16961697

1697-
return fds
1698+
// Remove the fdDir fd.
1699+
extraFd := strconv.Itoa(int(fdDir.Fd()))
1700+
return slices.DeleteFunc(fds, func(fd string) bool {
1701+
return fd == extraFd
1702+
})
16981703
}
16991704

17001705
func testFdLeaks(t *testing.T, systemd bool) {
@@ -1716,7 +1721,7 @@ func testFdLeaks(t *testing.T, systemd bool) {
17161721
runContainerOk(t, config, "true")
17171722
fds1 := fdList(t)
17181723

1719-
if reflect.DeepEqual(fds0, fds1) {
1724+
if slices.Equal(fds0, fds1) {
17201725
return
17211726
}
17221727
// Show the extra opened files.

0 commit comments

Comments
 (0)