Skip to content

Commit

Permalink
Merge pull request moby#21692 from tonistiigi/fix-events-timer
Browse files Browse the repository at this point in the history
Fix race with event timer stopping early
  • Loading branch information
calavera committed Mar 31, 2016
2 parents 00031c1 + b38cee9 commit 3e03fc9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions api/server/router/system/system_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
return err
}

timer := time.NewTimer(0)
timer.Stop()
var timeout <-chan time.Time
if until > 0 || untilNano > 0 {
dur := time.Unix(until, untilNano).Sub(time.Now())
timer = time.NewTimer(dur)
timeout = time.NewTimer(dur).C
}

ef, err := filters.FromParam(r.Form.Get("filters"))
Expand Down Expand Up @@ -94,7 +93,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
if err := enc.Encode(jev); err != nil {
return err
}
case <-timer.C:
case <-timeout:
return nil
case <-ctx.Done():
logrus.Debug("Client context cancelled, stop sending events")
Expand Down

0 comments on commit 3e03fc9

Please sign in to comment.