mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 02:01:36 +00:00
workaround to random timeouts
This commit is contained in:
parent
5d323861f0
commit
6469e39ff1
@ -48,13 +48,12 @@ func PutBytes(bs []byte) {
|
|||||||
|
|
||||||
// This is a workaround to go's broken timer implementation
|
// This is a workaround to go's broken timer implementation
|
||||||
func TimerStop(t *time.Timer) bool {
|
func TimerStop(t *time.Timer) bool {
|
||||||
if !t.Stop() {
|
stopped := t.Stop()
|
||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
return stopped
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run a blocking function with a timeout.
|
// Run a blocking function with a timeout.
|
||||||
|
@ -144,7 +144,7 @@ func (c *Conn) startSearch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getDeadlineTimer(value *atomic.Value) *time.Timer {
|
func getDeadlineTimer(value *atomic.Value) *time.Timer {
|
||||||
timer := time.NewTimer(0)
|
timer := time.NewTimer(24 * 365 * time.Hour) // FIXME for some reason setting this to 0 doesn't always let it stop and drain the channel correctly
|
||||||
util.TimerStop(timer)
|
util.TimerStop(timer)
|
||||||
if deadline, ok := value.Load().(time.Time); ok {
|
if deadline, ok := value.Load().(time.Time); ok {
|
||||||
timer.Reset(time.Until(deadline))
|
timer.Reset(time.Until(deadline))
|
||||||
|
Loading…
Reference in New Issue
Block a user