Skip to content

Commit 7c8bcf4

Browse files
authored
Merge pull request #499 from leancloud/fix-high-cpu
Fix high cpu usage caused by golang/go#33565
2 parents c9fd65c + 6c04a72 commit 7c8bcf4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

commands/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func Run(args []string) {
434434
if !ok || disableGA == "false" {
435435
args := []string{"--_collect-stats"}
436436
args = append(args, c.Args()...)
437-
_ = exec.Command(os.Args[0], args...).Start()
437+
StartBackgroundCommand(exec.Command(os.Args[0], args...))
438438
}
439439
return nil
440440
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
2+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
3+
4+
package commands
5+
6+
import (
7+
"os/exec"
8+
"runtime"
9+
"syscall"
10+
)
11+
12+
func StartBackgroundCommand(cmd *exec.Cmd) error {
13+
if runtime.GOOS == "darwin" {
14+
syscall.Sync() // workaround for https://github.com/golang/go/issues/33565
15+
}
16+
return cmd.Start()
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package commands
2+
3+
import "os/exec"
4+
5+
func StartBackgroundCommand(cmd *exec.Cmd) error {
6+
return cmd.Start()
7+
}

0 commit comments

Comments
 (0)