Skip to content

Commit

Permalink
Merge pull request containerd#10555 from zhsj/bpo-10346-1.6
Browse files Browse the repository at this point in the history
[release/1.6] Fix TestNewBinaryIOCleanup failing with gotip
  • Loading branch information
mxpv authored Aug 7, 2024
2 parents 492f9db + 4ec5cd6 commit 49fe601
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/process/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ package process

import (
"context"
"fmt"
"net/url"
"os"
"strings"
"testing"

"github.com/containerd/containerd/namespaces"
Expand Down Expand Up @@ -69,5 +71,28 @@ func TestNewBinaryIOCleanup(t *testing.T) {
func descriptorCount(t *testing.T) int {
t.Helper()
files, _ := os.ReadDir("/proc/self/fd")

// Go 1.23 introduced a new internal file descriptor type "pidfd"
// that we don't want to count towards the total file descriptors in
// use by the process. This retains the behavior of previous Go
// versions.
// See https://go.dev/issues/62654.
//
// Once the proposal to check for internal file descriptors is
// accepted, we can use that instead to detect internal fds in use
// by the Go runtime.
// See https://go.dev/issues/67639.
for i, file := range files {
sym, err := os.Readlink(fmt.Sprintf("/proc/self/fd/%s", file.Name()))
if err != nil {
// ignore fds that cannot be followed.
continue
}

if strings.HasPrefix(sym, "pidfd:") {
files = append(files[:i], files[i+1:]...)
}
}

return len(files)
}

0 comments on commit 49fe601

Please sign in to comment.