Skip to content

Commit e5faa0d

Browse files
committed
heartbeat: lock ForkLock for reading
Circumvents golang/go#22315
1 parent e064a55 commit e5faa0d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

testutil/heartbeat.go

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strconv"
99
"strings"
10+
"syscall"
1011
"testing"
1112
"time"
1213
)
@@ -36,6 +37,12 @@ type Heartbeat struct {
3637
func NewHeartbeat(t *testing.T) Heartbeat {
3738
t.Helper()
3839

40+
// Lock ForkLock whenever we are writing to a file that will execute shortly after, to prevent its FD from leaking
41+
// into a forked process and thus making exec fail with ETXBSY.
42+
// https://github.com/golang/go/issues/22315
43+
syscall.ForkLock.RLock()
44+
defer syscall.ForkLock.RUnlock()
45+
3946
dir := t.TempDir()
4047
scriptFile, err := os.OpenFile(filepath.Join(dir, "heartbeat.sh"), os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.FileMode(0o700))
4148
if err != nil {

0 commit comments

Comments
 (0)