rcrowley / go-metrics

Go port of Coda Hale's Metrics library
Other
3.43k stars 493 forks source link

Partial workaround for timer during a clock jump #196

Open vincentbernat opened 7 years ago

vincentbernat commented 7 years ago

time.Now() uses the wall-clock and therefore calling it twice, one second apart, can produce quite different results (negative results but also a difference greater than one second). Go doesn't expose a monotonic clock, therefore, it's difficult to properly fix (but there is https://github.com/gavv/monotime if we want a proper fix for timer.Time()).

This workaround just discard any negative duration.

There are other places that incorrectly uses time.Now(). I can add a similar check or I can import monotime to properly fixes them.