From 4b965591e94e13103a0fba73ba8ab2edf3f65d6e Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Mon, 17 Jun 2024 18:35:14 -0700 Subject: [PATCH] test: deflake runsc/boot:boot_test Due to Go's "zero value" semantics, raw FD values not explicitly specified in boot.Args default to 0 (stdin). In loader_test.go:TestHostnetWithRawSockets, which expects a call to boot.New() to fail, this causes the construction of a fd.FD for Args.ExecFD = 0 which is later closed unpredictably by finalizer. PiperOrigin-RevId: 644199565 --- runsc/boot/loader_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/runsc/boot/loader_test.go b/runsc/boot/loader_test.go index a7353b508..57f91219d 100644 --- a/runsc/boot/loader_test.go +++ b/runsc/boot/loader_test.go @@ -116,19 +116,20 @@ func createLoader(conf *config.Config, spec *specs.Spec) (*Loader, func(), error sock := fmt.Sprintf("\x00loader-test.%010d", rand.Int()) fd, err := server.CreateSocket(sock) if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("failed to create socket: %w", err) } sandEnd, cleanup, err := startGofer(spec.Root.Path, conf) if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("failed to start gofer: %w", err) } // Loader takes ownership of stdio. var stdio []int for _, f := range []*os.File{os.Stdin, os.Stdout, os.Stderr} { - newFd, err := unix.Dup(int(f.Fd())) + fd := int(f.Fd()) + newFd, err := unix.Dup(fd) if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("failed to dup FD %d: %w", fd, err) } stdio = append(stdio, newFd) } @@ -148,7 +149,7 @@ func createLoader(conf *config.Config, spec *specs.Spec) (*Loader, func(), error l, err := New(args) if err != nil { cleanup() - return nil, nil, err + return nil, nil, fmt.Errorf("boot.New: %w", err) } return l, cleanup, nil } @@ -273,9 +274,12 @@ func TestHostnetWithRawSockets(t *testing.T) { // Creating loader should fail. l, err := New(Args{ - ID: "should-fail", - Spec: testSpec(), - Conf: conf, + ID: "should-fail", + Spec: testSpec(), + Conf: conf, + DevGoferFD: -1, + PodInitConfigFD: -1, + ExecFD: -1, }) if err == nil { l.Destroy()