Skip to content

Commit 6ed20f7

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

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@ func (c *Command) Runnable() bool {
105105
}
106106

107107
var atExitFuncs []func()
108+
var atExitFuncsLock sync.Mutex
108109

109110
func AtExit(f func()) {
111+
atExitFuncsLock.Lock()
112+
defer atExitFuncsLock.Unlock()
110113
atExitFuncs = append(atExitFuncs, f)
111114
}
112115

113116
func Exit() {
117+
atExitFuncsLock.Lock()
114118
for _, f := range atExitFuncs {
115119
f()
116120
}
121+
atExitFuncsLock.Unlock()
117122
os.Exit(exitStatus)
118123
}
119124

0 commit comments

Comments
 (0)