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

Comments

Projects
None yet
4 participants
@gabriel
Copy link

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

This comment has been minimized.

Copy link
Author

commented Dec 28, 2016

@gabriel

This comment has been minimized.

Copy link
Author

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 this to the Unplanned milestone Dec 28, 2016

@bradfitz

This comment has been minimized.

Copy link
Member

commented Dec 28, 2016

Thanks for filing.

@gabriel

This comment has been minimized.

Copy link
Author

commented Dec 28, 2016

Another related/same issue: #12914

@namsral

This comment has been minimized.

Copy link
Contributor

commented Jan 11, 2017

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

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

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

@bradfitz bradfitz closed this Jan 11, 2017

@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.
You can’t perform that action at this time.