Merge pull request #10346 from mauri870/hotfix/gotip-test

Fix TestNewBinaryIOCleanup failing with gotip
This commit is contained in:
Phil Estes 2024-07-23 02:31:47 +00:00 committed by GitHub
commit 0fe79b6eac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,8 +20,10 @@ package process
import ( import (
"context" "context"
"fmt"
"net/url" "net/url"
"os" "os"
"strings"
"testing" "testing"
"github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/containerd/v2/pkg/namespaces"
@ -68,5 +70,28 @@ func TestNewBinaryIOCleanup(t *testing.T) {
func descriptorCount(t *testing.T) int { func descriptorCount(t *testing.T) int {
t.Helper() t.Helper()
files, _ := os.ReadDir("/proc/self/fd") 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) return len(files)
} }