1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix race between with event timer stopping early

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2016-03-31 09:48:20 -07:00
parent 61ca308676
commit b38cee9f9c

View file

@ -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"))
@ -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")