Skip to content

Commit

Permalink
goprocess: fix EMFILE error on macOS Catalina (#118)
Browse files Browse the repository at this point in the history
Limit the number of concurrent goroutines to avoid EMFILE on macOS Catalina.
  • Loading branch information
kumakichi authored Aug 5, 2020
1 parent 983b7ba commit b96604f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions goprocess/gp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type P struct {

// FindAll returns all the Go processes currently running on this host.
func FindAll() []P {
const concurrencyProcesses = 10 // limit the maximum number of concurrent reading process tasks
pss, err := ps.Processes()
if err != nil {
return nil
Expand All @@ -35,10 +36,13 @@ func FindAll() []P {
var wg sync.WaitGroup
wg.Add(len(pss))
found := make(chan P)
limitCh := make(chan struct{}, concurrencyProcesses)

for _, pr := range pss {
limitCh <- struct{}{}
pr := pr
go func() {
defer func() { <-limitCh }()
defer wg.Done()

path, version, agent, ok, err := isGo(pr)
Expand Down

0 comments on commit b96604f

Please sign in to comment.