Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test code to verify fd leaks #9414

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ COPY --chmod=0644 hack/cri-containerd.toml /rootfs/etc/cri/containerd.toml
COPY --chmod=0644 hack/cri-plugin.part /rootfs/etc/cri/conf.d/00-base.part
COPY --chmod=0644 hack/udevd/80-net-name-slot.rules /rootfs/usr/lib/udev/rules.d/
COPY --chmod=0644 hack/lvm.conf /rootfs/etc/lvm/lvm.conf
COPY --chmod=0755 hack/fdspy/fdspy /rootfs/usr/bin/fdspy
RUN <<END
ln -s /usr/share/zoneinfo/Etc/UTC /rootfs/etc/localtime
touch /rootfs/etc/{extensions.yaml,resolv.conf,hosts,os-release,machine-id,cri/conf.d/cri.toml,cri/conf.d/01-registries.part,cri/conf.d/20-customization.part,ssl/certs/ca-certificates}
Expand Down
3 changes: 3 additions & 0 deletions hack/fdspy/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/siderolabs/fdspy

go 1.23.1
28 changes: 28 additions & 0 deletions hack/fdspy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package main

import (
"fmt"
"os"
)

func main() {
fds, err := os.ReadDir("/proc/self/fd")
if err != nil {
panic(err)
}

for _, fd := range fds {
fname, err := os.Readlink(fmt.Sprintf("/proc/self/fd/%s", fd.Name()))
if err != nil {
fmt.Fprintln(os.Stderr, fd.Name(), " --> ", err)
} else {
fmt.Fprintln(os.Stderr, fd.Name(), " --> ", fname)
}
}

os.Exit(1)
}
57 changes: 57 additions & 0 deletions internal/app/machined/pkg/controllers/runtime/fdspy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package runtime

import (
"context"
"fmt"
"time"

"github.com/cosi-project/runtime/pkg/controller"
"github.com/siderolabs/go-cmd/pkg/cmd"
"go.uber.org/zap"
)

// FDSpyController activates LVM volumes when they are discovered by the block.DiscoveryController.
type FDSpyController struct {
}

// Name implements controller.Controller interface.
func (ctrl *FDSpyController) Name() string {
return "runtime.FDSpyController"
}

// Inputs implements controller.Controller interface.
func (ctrl *FDSpyController) Inputs() []controller.Input {
return nil
}

// Outputs implements controller.Controller interface.
func (ctrl *FDSpyController) Outputs() []controller.Output {
return nil
}

// Run implements controller.Controller interface.
//
//nolint:gocyclo
func (ctrl *FDSpyController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return nil
case <-r.EventCh():
case <-ticker.C:
}

if _, err := cmd.RunContext(ctx,
"/usr/bin/fdspy",
); err != nil {
return fmt.Errorf("failed to run fdspy: %w", err)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func (ctrl *Controller) Run(ctx context.Context, drainer *runtime.Drainer) error
ConfigPath: constants.ExtensionServiceConfigPath,
},
&runtimecontrollers.ExtensionStatusController{},
&runtimecontrollers.FDSpyController{},
&runtimecontrollers.KernelModuleConfigController{},
&runtimecontrollers.KernelModuleSpecController{
V1Alpha1Mode: ctrl.v1alpha1Runtime.State().Platform().Mode(),
Expand Down
Loading