Fix events timeout errors
Resetting the timeout doesn't fully cut it, as it may timeout after we got an event and be delivered later. This should fix it well enough for the moment. https://github.com/golang/go/issues/11513
This commit is contained in:
@@ -188,12 +188,19 @@ func (s *Subscription) Poll(timeout time.Duration) (Event, error) {
|
||||
dl.Debugln("poll", timeout)
|
||||
}
|
||||
|
||||
s.timeout.Reset(timeout)
|
||||
if !s.timeout.Reset(timeout) {
|
||||
select {
|
||||
case <-s.timeout.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
case e, ok := <-s.events:
|
||||
if !ok {
|
||||
return e, ErrClosed
|
||||
}
|
||||
s.timeout.Stop()
|
||||
return e, nil
|
||||
case <-s.timeout.C:
|
||||
return Event{}, ErrTimeout
|
||||
|
||||
Reference in New Issue
Block a user