rickover icon indicating copy to clipboard operation
rickover copied to clipboard

Library can measure negative times

Open kevinburke opened this issue 8 years ago • 6 comments

Occasionally the duration reported by calling a := time.Now(); b := time.Now(); c := b.Since(a) can be negative, since Go does not use a monotonic clock source for time.Now() calls. This affected production code after the leap second yesterday. This is being discussed at e.g. https://github.com/golang/go/issues/12914 but it might be good to consider switching to something like https://godoc.org/github.com/davecheney/junk/clock in the meantime.

I'm still researching this issue.

kevinburke avatar Jan 02 '17 07:01 kevinburke

Fascinating. 🍿!

I like how the test in https://github.com/aristanetworks/goarista/commit/46272bfb1c042fc2825d312fe33d494e9d13dd6b looks to be probabilistic, I guess you'd have to actually mess with the system time or do some horrendous mocking to pull off a deterministic test though.

And interesting that this conversation flared up again because Cloudflare had some downtime due to it. In general though, absent an admin messing with the system time, are time leaping and DST type of events the main places where this would cause a problem?

dav avatar Jan 02 '17 16:01 dav

(I'm using this library: https://godoc.org/github.com/aristanetworks/goarista/monotime)

kevinburke avatar Jan 02 '17 17:01 kevinburke

(In the grand scheme of things I doubt this matters much since I'm pretty confident the system can tolerate a negative time measurement. But it's good to do the right thing)

kevinburke avatar Jan 02 '17 17:01 kevinburke

I wrote more about it here https://kev.inburke.com/kevin/leap-seconds/

kevinburke avatar Jan 04 '17 01:01 kevinburke

A monotonic clock is probably coming in Go 1.9 https://github.com/golang/go/issues/12914

kevinburke avatar Jan 27 '17 07:01 kevinburke

🙌 that's awesome

ianmdawson avatar Jan 27 '17 17:01 ianmdawson