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

runtime: use monotonic time on darwin #18455

Closed
gabriel opened this issue Dec 28, 2016 · 6 comments
Closed

runtime: use monotonic time on darwin #18455

gabriel opened this issue Dec 28, 2016 · 6 comments
Labels
FrozenDueToAge help wanted OS-Darwin Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@gabriel
Copy link

gabriel commented Dec 28, 2016

What version of Go are you using (go version)?

go version go1.7.4 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/vm/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.4/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.4/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y9/b0pxmq754gn9spczf1cw_sq80000gn/T/go-build998056904=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

If you have a loop with time.Sleep(time.Second) and you set the clock back (for example, an hour), the time.Sleep will hang for that amount of time (an hour), instead of 1s.

Run this:

package main

import (
	"fmt"
	"time"
)

func main() {
	for {
		fmt.Printf("Sleeping 1s (%s)\n", time.Now())
		time.Sleep(time.Second)
	}
}

And then set the clock back an minute or hour, or however much time you want it to hang.

What did you expect to see?

I expect time.Sleep not be affected by clock changes (or skew).

What did you see instead?

The time.Sleep will hang (for a minute or however long you set the clock back).

@gabriel
Copy link
Author

gabriel commented Dec 28, 2016

Some discussion here about this:
https://groups.google.com/forum/#!msg/golang-dev/gVFa7DC8UI0/3gfW_2bV1U4J

@gabriel
Copy link
Author

gabriel commented Dec 28, 2016

Related issue: #6007

@bradfitz bradfitz changed the title time.Sleep hangs if clock is set back runtime: use monotonic time on darwin Dec 28, 2016
@bradfitz bradfitz added OS-Darwin Suggested Issues that may be good for new contributors looking for work to do. labels Dec 28, 2016
@bradfitz bradfitz added this to the Unplanned milestone Dec 28, 2016
@bradfitz
Copy link
Contributor

Thanks for filing.

@gabriel
Copy link
Author

gabriel commented Dec 28, 2016

Another related/same issue: #12914

@namsral
Copy link
Contributor

namsral commented Jan 11, 2017

Possible fix by using mach_absolute_time for runtime.nanotime as mentioned in #17610

@bradfitz
Copy link
Contributor

@namsral, thanks for pointing out that this is a dup of #17610. I'll close this one.

@golang golang locked and limited conversation to collaborators Jan 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted OS-Darwin Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

4 participants