Skip to content

Commit

Permalink
Do not leak goroutines (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex2108 committed May 26, 2016
1 parent 0091c1b commit c7cc95f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 4 additions & 2 deletions initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ func initializeLocked() {
}
err = get_config()
}
eventChan = make(chan event,10000)
go eventProcessor() //start processing events again
// let old events be processed to start with a clean event channel
for len(eventChan)>0 {
time.Sleep(time.Millisecond)
}
eventMutex.Unlock()
mutex.Unlock()
// get current state
Expand Down
12 changes: 4 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os/signal"
"syscall"
"time"
"errors"
"sync"
)

Expand Down Expand Up @@ -108,7 +107,7 @@ func readEvents() error {
}


func eventProcessor() error {
func eventProcessor() {
for event := range eventChan {
mutex.Lock() // mutex with initialitze which may still be running
// handle different events
Expand Down Expand Up @@ -137,14 +136,10 @@ func eventProcessor() error {
log.Println("got new config -> reinitialize")
since_events = event.ID
mutex.Unlock()
defer initialize()
return errors.New("got new config")


initialize()
}
mutex.Unlock()
}
return nil
}


Expand Down Expand Up @@ -275,9 +270,10 @@ func main() {
log.Println("Connecting to syncthing at", config.Url)
trayMutex.Lock()
go rate_reader()
go eventProcessor()
go func() {
initialize()
main_loop()
main_loop()

}()

Expand Down

0 comments on commit c7cc95f

Please # to comment.