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

time: After delay 10s occasionally #21746

Closed
sisyphsu opened this issue Sep 3, 2017 · 5 comments
Closed

time: After delay 10s occasionally #21746

sisyphsu opened this issue Sep 3, 2017 · 5 comments

Comments

@sisyphsu
Copy link

sisyphsu commented Sep 3, 2017

Version: go version go1.8.3 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sulin/workspace/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j0/z8rksv5911g9kwyfffq5y1rr0000gn/T/go-build131871117=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

When i use time.After for some short sleep, mostly 10ms~100ms.
I found the timer didn't expire at the expected time, but delay 10 seconds. this was occasionally, like 1/1000, but it really ruin my application.

The code is blow:

for !s._close {
    p := newProtocol()
    s.Lock()
    delay := s.fec.onSend(p)
    s.Unlock()
    startTime := time.Now().UnixNano()
    select {
    case <-time.After(delay):
        LOGGER.TraceF("normal %v: %v", delay, time.Duration(time.Now().UnixNano()-startTime))
    case <-s.signal:
        LOGGER.TraceF("break %v: %v", delay, time.Duration(time.Now().UnixNano()-startTime))
    }
}

Most log didn't delay much, like 10ms->12ms, I could accept it.

2017-09-03 16:18:18.094617288 [TRACE] normal 7.953537ms: 9.151017ms
2017-09-03 16:18:18.145271958 [TRACE] normal 8.877516ms: 10.193023ms
2017-09-03 16:18:18.220673023 [TRACE] normal 19.940444ms: 22.052824ms
2017-09-03 16:19:12.85975685  [TRACE] normal 10.94034ms: 13.224514ms
2017-09-03 16:19:12.885154309 [TRACE] normal 21.935108ms: 25.278368ms

But sometimes, the timer will delay very much, like 10ms->10s.

2017-09-03 16:18:52.915667148 [TRACE] normal 10.974347ms: 9.162969872s
2017-09-03 16:18:57.783207779 [TRACE] normal 21.896961ms: 4.867348206s
@davecheney
Copy link
Contributor

davecheney commented Sep 3, 2017 via email

@sisyphsu
Copy link
Author

sisyphsu commented Sep 3, 2017

@davecheney OK, thanks.

@cznic
Copy link
Contributor

cznic commented Sep 3, 2017

FTR: time.After(x) semantics are such that the receive from the returned channel occurs not before x, ie. any time later on non-RT OSes and not much more can be guaranteed.

Additionally to what @davecheney wrote, it could be helpful to know also the value received from the channel, to distinguish if the delay is on the send or receive side.

@mdempsky mdempsky changed the title time.After delay 10s occasionally time: After delay 10s occasionally Sep 5, 2017
@sisyphsu
Copy link
Author

sisyphsu commented Sep 6, 2017

After upgrade Go to 1.9, this issue didn't appear anymore, and I can't find the reason...

I will keep watching my log, should I close this issue temporary?

@ianlancetaylor
Copy link
Contributor

If you can't recreate the problem with 1.9, let's close the issue. Thanks.

@golang golang locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants