Skip to content

Commit 9e3bfd5

Browse files
tonistiigiTibor Vass
authored andcommitted
Fix race between with event timer stopping early
Signed-off-by: Tonis Tiigi <[email protected]> (cherry picked from commit b38cee9)
1 parent bab77d4 commit 9e3bfd5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

api/server/router/system/system_routes.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
5555
return err
5656
}
5757

58-
timer := time.NewTimer(0)
59-
timer.Stop()
58+
var timeout <-chan time.Time
6059
if until > 0 || untilNano > 0 {
6160
dur := time.Unix(until, untilNano).Sub(time.Now())
62-
timer = time.NewTimer(dur)
61+
timeout = time.NewTimer(dur).C
6362
}
6463

6564
ef, err := filters.FromParam(r.Form.Get("filters"))
@@ -99,7 +98,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
9998
if err := enc.Encode(jev); err != nil {
10099
return err
101100
}
102-
case <-timer.C:
101+
case <-timeout:
103102
return nil
104103
case <-closeNotify:
105104
logrus.Debug("Client disconnected, stop sending events")

0 commit comments

Comments
 (0)