Skip to content

Commit 13faa5c

Browse files
committed
cmd/go: fix data race in TestScript
Fixes golang#54423
1 parent 2f6783c commit 13faa5c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: src/cmd/go/internal/base/base.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,23 @@ func (c *Command) Runnable() bool {
104104
return c.Run != nil
105105
}
106106

107-
var atExitFuncs []func()
107+
var (
108+
atExitFuncsLock sync.Mutex
109+
atExitFuncs []func()
110+
)
108111

109112
func AtExit(f func()) {
113+
atExitFuncsLock.Lock()
114+
defer atExitFuncsLock.Unlock()
110115
atExitFuncs = append(atExitFuncs, f)
111116
}
112117

113118
func Exit() {
119+
atExitFuncsLock.Lock()
114120
for _, f := range atExitFuncs {
115121
f()
116122
}
123+
atExitFuncsLock.Unlock()
117124
os.Exit(exitStatus)
118125
}
119126

0 commit comments

Comments
 (0)