My go version is 1.11.
When I set time.Location, then …
==================
WARNING: DATA RACE
Write at 0x000002e275d0 by main goroutine:
vcs.taiyouxi.net/platform/planx/timeutil.SetTimeLocal()
/Users/zhangzhen/serverthreekingdom/src/vcs.taiyouxi.net/platform/planx/timeutil/time_util.go:51 +0xb4
vcs.taiyouxi.net/platform/planx/timeutil.init.0()
/Users/zhangzhen/serverthreekingdom/src/vcs.taiyouxi.net/platform/planx/timeutil/time_util.go:42 +0x43
vcs.taiyouxi.net/platform/planx/timeutil.init()
<autogenerated>:1 +0xd0
vcs.taiyouxi.net/jws2/common/time.init()
<autogenerated>:1 +0xa6
vcs.taiyouxi.net/jws2/gamex/account/account.init()
<autogenerated>:1 +0xa6
vcs.taiyouxi.net/jws2/gamex/logics.init()
<autogenerated>:1 +0xa6
vcs.taiyouxi.net/jws2/gamex/cmds/gamemode.init()
<autogenerated>:1 +0xa6
main.init()
<autogenerated>:1 +0xa6
Previous read at 0x000002e275d0 by goroutine 8:
time.Now()
/Users/zhangzhen/.gvm/gos/go1.11/src/time/time.go:1060 +0xcf
time.sendTime()
/Users/zhangzhen/.gvm/gos/go1.11/src/time/sleep.go:141 +0x44
Goroutine 8 (running) created at:
runtime.(*timersBucket).addtimerLocked()
/Users/zhangzhen/.gvm/gos/go1.11/src/runtime/time.go:170 +0x113
vcs.taiyouxi.net/vendor/github.com/siddontang/go/timingwheel.NewTimingWheel()
/Users/zhangzhen/serverthreekingdom/src/vcs.taiyouxi.net/vendor/github.com/siddontang/go/timingwheel/timingwheel.go:39 +0x2a0
vcs.taiyouxi.net/platform/planx/util.init()
/Users/zhangzhen/serverthreekingdom/src/vcs.taiyouxi.net/platform/planx/util/timer_helper.go:10 +0xf3
vcs.taiyouxi.net/platform/planx/metrics.init()
<autogenerated>:1 +0xbf
vcs.taiyouxi.net/jws2/gamex/cmds/gamemode.init()
<autogenerated>:1 +0x9c
main.init()
<autogenerated>:1 +0xa6
==================
The feature of golang is goroutine, and it is a normal situation that get time in different goroutine.
But only can set time.Location in one goroutine. So the Data Race is inevitable.
And there is the replay from agnivade
“It is not a bug. Please synchronize access to time.Location using synchronization primitives in the sync
and sync/atomic
packages.”
But there are lots of place that time.Location used by time package of golang. For example: time.Now(), time.locabs()
I can’t change them.
So, What should I do ? Please help me.