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:
Jakob Borg
2015-08-24 09:38:39 +02:00
parent 98effcd8e3
commit d6e34761dc
2 changed files with 18 additions and 3 deletions

View File

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