Skip to content

Commit

Permalink
Fix main goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Oct 9, 2014
1 parent 5f883e0 commit 758995d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package main

import (
"io"
"time"
)

func Start(stop chan int) {
for _, in := range Plugins.Inputs {
go CopyMulty(in, Plugins.Outputs...)
}

select {
case <-stop:
return
for {
select {
case <-stop:
return
case <- time.After(1 * time.Second):
}
}
}

Expand Down

2 comments on commit 758995d

@joekiller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buger is this change still necessary? I remember you saying it was a blind fix somewhat. If it is an improvement what does it do? Just curious. Always learning here.

@buger
Copy link
Owner Author

@buger buger commented on 758995d Oct 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default select is blocking and if it will block and no other goroutines running it means that app hanged. time.After(1 * time.Second) creates special channel (with background goroutine) which unfreeze this select every 1 second (1 second not really matter, it can be any value).

Such bug can happen when using --input-file which does not have any goroutines, and output without goroutines as well. Your first dynamic scaling attempt had bug when all workers are dead.

Please sign in to comment.