Merge pull request #6185 from heyitsanthony/wait-time-collision

wait: make WaitTime robust against deadline collisions
This commit is contained in:
Anthony Romano 2016-08-15 15:15:29 -07:00 committed by GitHub
commit 961b03420e

View File

@ -43,8 +43,16 @@ func (tl *timeList) Wait(deadline time.Time) <-chan struct{} {
tl.l.Lock()
defer tl.l.Unlock()
ch := make(chan struct{}, 1)
// The given deadline SHOULD be unique.
tl.m[deadline.UnixNano()] = ch
// The given deadline SHOULD be unique but CI manages to get
// the same nano time in the unit tests.
nano := deadline.UnixNano()
for {
if tl.m[nano] == nil {
tl.m[nano] = ch
break
}
nano++
}
return ch
}