Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library can measure negative times #9

Open
kevinburke opened this issue Jan 2, 2017 · 6 comments
Open

Library can measure negative times #9

kevinburke opened this issue Jan 2, 2017 · 6 comments

Comments

@kevinburke
Copy link
Contributor

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. golang/go#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
Copy link

dav commented Jan 2, 2017

Fascinating. 🍿!

I like how the test in aristanetworks/goarista@46272bf 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
Copy link
Contributor Author

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

@kevinburke
Copy link
Contributor Author

(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
Copy link
Contributor Author

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

@kevinburke
Copy link
Contributor Author

A monotonic clock is probably coming in Go 1.9 golang/go#12914

@ianmdawson
Copy link
Contributor

🙌 that's awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants