Skip to content

Commit 3323dab

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
os/exec: retry ETXTBSY errors in TestFindExecutableVsNoexec
I made this test parallel in CL 439196, which exposed it to the fork/exec race condition described in #22315. The ETXTBSY errors from that race should resolve on their own, so we can simply retry the call to get past them. Fixes #56811. Updates #22315. Change-Id: I2c6aa405bf3a1769d69cf08bf661a9e7f86440b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/458016 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 628a1e7 commit 3323dab

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/os/exec/lp_linux_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package exec
66

77
import (
8+
"errors"
89
"internal/syscall/unix"
910
"os"
1011
"path/filepath"
@@ -48,8 +49,20 @@ func TestFindExecutableVsNoexec(t *testing.T) {
4849
t.Fatalf("findExecutable: got %v, want nil", err)
4950
}
5051

51-
if err := Command(path).Run(); err != nil {
52-
t.Fatalf("exec: got %v, want nil", err)
52+
for {
53+
err = Command(path).Run()
54+
if err == nil {
55+
break
56+
}
57+
if errors.Is(err, syscall.ETXTBSY) {
58+
// A fork+exec in another process may be holding open the FD that we used
59+
// to write the executable (see https://go.dev/issue/22315).
60+
// Since the descriptor should have CLOEXEC set, the problem should resolve
61+
// as soon as the forked child reaches its exec call.
62+
// Keep retrying until that happens.
63+
} else {
64+
t.Fatalf("exec: got %v, want nil", err)
65+
}
5366
}
5467

5568
// Remount with noexec flag.

0 commit comments

Comments
 (0)