Skip to content

Commit

Permalink
move defer out of loop so as not to leak a closure (#488)
Browse files Browse the repository at this point in the history
* move defer out of loop so as not to leak a closure
* move handleSignals out of run loop because we never cancel it
  • Loading branch information
tgross authored Aug 21, 2017
1 parent 229c3a6 commit 5e88da2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func getEnvVarNameFromService(service string) string {

// Run starts the application and blocks until finished
func (a *App) Run() {
a.handleSignals()
for {
a.Bus = events.NewEventBus()
a.ControlServer.Run(a.Bus)
a.handleSignals()
a.handlePolling()
if !a.Bus.Wait() {
if a.StopTimeout > 0 {
Expand Down
14 changes: 7 additions & 7 deletions events/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ func NewEventTimer(
) {
go func() {
ticker := time.NewTicker(tick)
// sending the timeout event potentially races with a closing
// rx channel, so just recover from the panic and exit
defer func() {
if r := recover(); r != nil {
return
}
}()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
// sending the timeout event potentially races with a closing
// rx channel, so just recover from the panic and exit
defer func() {
if r := recover(); r != nil {
return
}
}()
rx <- Event{Code: TimerExpired, Source: name}
}
}
Expand Down

0 comments on commit 5e88da2

Please sign in to comment.