Shyp / rickover

A job queue and scheduler written in Go, backed by Postgres, and available over HTTP
https://godoc.org/github.com/Shyp/rickover
MIT License
182 stars 21 forks source link

Library can measure negative times #9

Open kevinburke opened 7 years ago

kevinburke commented 7 years ago

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.

dav commented 7 years ago

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?

kevinburke commented 7 years ago

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

kevinburke commented 7 years ago

(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 commented 7 years ago

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

kevinburke commented 7 years ago

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

ianmdawson commented 7 years ago

🙌 that's awesome