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

a panic occurs when using tls.ID(), and gis is recommended instead of tls #31

Open
xiaobai-tx opened this issue Oct 24, 2022 · 1 comment

Comments

@xiaobai-tx
Copy link

xiaobai-tx commented Oct 24, 2022

I get a panic when I use tls.ID(), but I'm not sure how it works.

My version of Go?
go version go1.19.1 windows/amd64

Operating system?
win10

Here is my code, it comes from parallel_test.go

var (
	m     = make(map[int64]int, 20)
	mu    sync.Mutex
	round int64 = 1
)

func BenchmarkParallel(b *testing.B) {
	fmt.Printf("\ngoroutine[%d] enter BenchmarkParalell: round[%d], b.N[%d]\n",
		tls.ID(), atomic.LoadInt64(&round), b.N)
	defer func() {
		atomic.AddInt64(&round, 1)
	}()

	b.RunParallel(func(pb *testing.PB) {
		id := tls.ID()
		fmt.Printf("goroutine[%d] enter loop func in BenchmarkParalell: round[%d], b.N[%d]\n", tls.ID(), atomic.LoadInt64(&round), b.N)
		for pb.Next() {
			mu.Lock()
			_, ok := m[id]
			if !ok {
				m[id] = 1
			} else {
				m[id] = m[id] + 1
			}
			mu.Unlock()
		}

		mu.Lock()
		count := m[id]
		mu.Unlock()

		fmt.Printf("goroutine[%d] exit loop func in BenchmarkParalell: round[%d], loop[%d]\n", tls.ID(), atomic.LoadInt64(&round), count)
	})

	fmt.Printf("goroutine[%d] exit BenchmarkParalell: round[%d], b.N[%d]\n",
		tls.ID(), atomic.LoadInt64(&round), b.N)
}

Run this code with 'go test -bench . parallel_test.go -cpu=2', and it will occur panic:

goroutine[1] enter BenchmarkParalell: round[1], b.N[1]                          
goroutine[2] enter loop func in BenchmarkParalell: round[1], b.N[1]             
goroutine[2] exit loop func in BenchmarkParalell: round[1], loop[1]             
fatal error: goroutine[3] enter loop func in BenchmarkParalell: round[1], b.N[1]
faultgoroutine[3] exit loop func in BenchmarkParalell: round[1], loop[0]        
                                                                                
fatal error: fault                                                              
[signal 0xc000001d code=0x0 addr=0x0 pc=0xdd53e1]                               
                                                                                
goroutine 69 [running]:                                                         
runtime.throw({0xe0a8ca?, 0xc0000c2240?})                                                                       
        C:/Program Files/Go/src/runtime/panic.go:1047 +0x65 fp=0xc000057f98 sp=0xc000057f68 pc=0xcf9865         
runtime.sigpanic()                                                                                              
        C:/Program Files/Go/src/runtime/signal_windows.go:273 +0x1af fp=0xc000057fe0 sp=0xc000057f98 pc=0xd0cc0f
runtime: g 69: unexpected return pc for github.com/huandu/go-tls.hackedGoexit called from 0x0                   
stack: frame={sp:0xc000057fe0, fp:0xc000057fe8} stack=[0xc000056000,0xc000058000)
0x000000c000057ee0:  0x0000000000000003  0x0000000000000002
0x000000c000057ef0:  0x0000000000000001  0x0000000000000000
0x000000c000057f00:  0x0000000000000001  0x000000c0000c2240
0x000000c000057f10:  0x0000000000de5120  0x0000000000d260d5 <runtime.systemstack+0x0000000000000035>
0x000000c000057f20:  0x0000000000cf9bac <runtime.fatalthrow+0x000000000000006c>  0x000000c000057f38
0x000000c000057f30:  0x000000c000084680  0x0000000000cf9be0 <runtime.fatalthrow.func1+0x0000000000000000>
0x000000c000057f40:  0x000000c000084680  0x0000000000cf9865 <runtime.throw+0x0000000000000065>
0x000000c000057f50:  0x000000c000057f68  0x000000c000057f88
0x000000c000057f60:  0x0000000000cf9865 <runtime.throw+0x0000000000000065>  0x000000c000057f70
0x000000c000057f70:  0x0000000000cf9880 <runtime.throw.func1+0x0000000000000000>  0x0000000000e0a8ca
0x000000c000057f80:  0x0000000000000005  0x000000c000057fd0
0x000000c000057f90:  0x0000000000d0cc0f <runtime.sigpanic+0x00000000000001af>  0x0000000000e0a8ca
0x000000c000057fa0:  0x000000c0000c2240  0x000000c000086098
0x000000c000057fb0:  0x000000c000084680  0x0000000000d802a0 <testing.(*B).RunParallel.func1.1+0x0000000000000000>
0x000000c000057fc0:  0x000000c0000860a0  0x000000c000057fb8
0x000000c000057fd0:  0x0000000000000000  0x0000000000dd53e1 <github.com/huandu/go-tls.hackedGoexit+0x0000000000000001>
0x000000c000057fe0: <0x0000000000000000 >0x0000000000000000
0x000000c000057ff0:  0x0000000000000000  0x0000000000000000
github.com/huandu/go-tls.hackedGoexit()
        ?:0 +0x1 fp=0xc000057fe8 sp=0xc000057fe0 pc=0xdd53e1
created by testing.(*B).RunParallel
        C:/Program Files/Go/src/testing/benchmark.go:781 +0x105

goroutine 1 [chan receive]:
runtime.gopark(0x30000?, 0xc0000cb960?, 0xdf?, 0xd8?, 0x8?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0000458e0 sp=0xc0000458c0 pc=0xcfc336
runtime.chanrecv(0xc000050180, 0x0, 0x1)
        C:/Program Files/Go/src/runtime/chan.go:583 +0x49b fp=0xc000045970 sp=0xc0000458e0 pc=0xcc6b3b
runtime.chanrecv1(0xcd9846?, 0xf616e0?)
        C:/Program Files/Go/src/runtime/chan.go:442 +0x18 fp=0xc000045998 sp=0xc000045970 pc=0xcc6678
testing.(*B).run1(0xc0000c2240)
        C:/Program Files/Go/src/testing/benchmark.go:235 +0xb2 fp=0xc000045a58 sp=0xc000045998 pc=0xd7cf52
testing.(*B).Run(0xc0000c2000, {0xe0d8b3?, 0x142b94ac1e70?}, 0xe18390)
        C:/Program Files/Go/src/testing/benchmark.go:676 +0x445 fp=0xc000045b40 sp=0xc000045a58 pc=0xd7f945
testing.runBenchmarks.func1(0xc0000c2000?)
        C:/Program Files/Go/src/testing/benchmark.go:550 +0x6e fp=0xc000045b90 sp=0xc000045b40 pc=0xd7ebce
testing.(*B).runN(0xc0000c2000, 0x1)
        C:/Program Files/Go/src/testing/benchmark.go:193 +0x102 fp=0xc000045c08 sp=0xc000045b90 pc=0xd7cd22
testing.runBenchmarks({0x0, 0x0}, 0xf60c40?, {0xf05740, 0x5, 0xcd741c?})
        C:/Program Files/Go/src/testing/benchmark.go:559 +0x418 fp=0xc000045d08 sp=0xc000045c08 pc=0xd7e878
testing.(*M).Run(0xc00009c000)
        C:/Program Files/Go/src/testing/testing.go:1733 +0x811 fp=0xc000045f00 sp=0xc000045d08 pc=0xd8a491
main.main()
        _testmain.go:55 +0x1aa fp=0xc000045f80 sp=0xc000045f00 pc=0xdd616a
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:250 +0x1fe fp=0xc000045fe0 sp=0xc000045f80 pc=0xcfbf9e
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000045fe8 sp=0xc000045fe0 pc=0xd283e1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000039fb0 sp=0xc000039f90 pc=0xcfc336
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.forcegchelper()
        C:/Program Files/Go/src/runtime/proc.go:302 +0xb1 fp=0xc000039fe0 sp=0xc000039fb0 pc=0xcfc1d1
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000039fe8 sp=0xc000039fe0 pc=0xd283e1
created by runtime.init.6
        C:/Program Files/Go/src/runtime/proc.go:290 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0xf0ab01?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00003bf90 sp=0xc00003bf70 pc=0xcfc336
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
        C:/Program Files/Go/src/runtime/mgcsweep.go:297 +0xd7 fp=0xc00003bfc8 sp=0xc00003bf90 pc=0xce4937
runtime.gcenable.func1()
        C:/Program Files/Go/src/runtime/mgc.go:178 +0x26 fp=0xc00003bfe0 sp=0xc00003bfc8 pc=0xcd9486
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00003bfe8 sp=0xc00003bfe0 pc=0xd283e1
created by runtime.gcenable
        C:/Program Files/Go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x142cc2fa8a18?, 0xf355c?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000047f70 sp=0xc000047f50 pc=0xcfc336
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.(*scavengerState).park(0xf0ad20)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:389 +0x53 fp=0xc000047fa0 sp=0xc000047f70 pc=0xce2973
runtime.bgscavenge(0x0?)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:622 +0x65 fp=0xc000047fc8 sp=0xc000047fa0 pc=0xce2f85
runtime.gcenable.func2()
        C:/Program Files/Go/src/runtime/mgc.go:179 +0x26 fp=0xc000047fe0 sp=0xc000047fc8 pc=0xcd9426
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000047fe8 sp=0xc000047fe0 pc=0xd283e1
created by runtime.gcenable
        C:/Program Files/Go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [finalizer wait]:
runtime.gopark(0x0?, 0xc00003de70?, 0xab?, 0x68?, 0xc00003df70?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00003de28 sp=0xc00003de08 pc=0xcfc336
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.runfinq()
        C:/Program Files/Go/src/runtime/mfinal.go:180 +0x10f fp=0xc00003dfe0 sp=0xc00003de28 pc=0xcd858f
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00003dfe8 sp=0xc00003dfe0 pc=0xd283e1
created by runtime.createfing
        C:/Program Files/Go/src/runtime/mfinal.go:157 +0x45

goroutine 18 [GC worker (idle)]:
runtime.gopark(0x142d02f2b168?, 0xd283e1?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000049f50 sp=0xc000049f30 pc=0xcfc336
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000049fe0 sp=0xc000049f50 pc=0xcdb691
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000049fe8 sp=0xc000049fe0 pc=0xd283e1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 7 [GC worker (idle)]:
runtime.gopark(0x142d02f2b168?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000043f50 sp=0xc000043f30 pc=0xcfc336
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000043fe0 sp=0xc000043f50 pc=0xcdb691
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000043fe8 sp=0xc000043fe0 pc=0xd283e1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 46 [runnable]:
runtime.gopark(0xc0000d5d70?, 0xcd68ab?, 0x20?, 0xc1?, 0xccd8df?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0000d5d30 sp=0xc0000d5d10 pc=0xcfc336
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.semacquire1(0xc0000860a8, 0xf0?, 0x1, 0x0)
        C:/Program Files/Go/src/runtime/sema.go:150 +0x20f fp=0xc0000d5d98 sp=0xc0000d5d30 pc=0xd0b64f
sync.runtime_Semacquire(0xc0001166f0?)
        C:/Program Files/Go/src/runtime/sema.go:62 +0x25 fp=0xc0000d5dc8 sp=0xc0000d5d98 pc=0xd23b45
sync.(*WaitGroup).Wait(0x0?)
        C:/Program Files/Go/src/sync/waitgroup.go:139 +0x52 fp=0xc0000d5df0 sp=0xc0000d5dc8 pc=0xd31e32
testing.(*B).RunParallel(0xc0000c2240, 0xc0000940f0)
        C:/Program Files/Go/src/testing/benchmark.go:791 +0x1c9 fp=0xc0000d5e68 sp=0xc0000d5df0 pc=0xd80109
command-line-arguments.BenchmarkParallel(0xc0000c2240)
        D:/Develop/tx/tx-go/gomaster/benchexamples/parallel_test.go:83 +0x171 fp=0xc0000d5f28 sp=0xc0000d5e68 pc=0xdd5a11
testing.(*B).runN(0xc0000c2240, 0x1)
        C:/Program Files/Go/src/testing/benchmark.go:193 +0x102 fp=0xc0000d5fa0 sp=0xc0000d5f28 pc=0xd7cd22
testing.(*B).run1.func1()
        C:/Program Files/Go/src/testing/benchmark.go:233 +0x59 fp=0xc0000d5fe0 sp=0xc0000d5fa0 pc=0xd7d2f9
fatal error: unexpected signal during runtime execution
panic during panic
[signal 0xc0000005 code=0x0 addr=0xe8 pc=0xd1c176]

runtime stack:
runtime.throw({0xe15231?, 0xee9ce0?})
        C:/Program Files/Go/src/runtime/panic.go:1047 +0x65 fp=0xe00ebff570 sp=0xe00ebff540 pc=0xcf9865
runtime.sigpanic()
        C:/Program Files/Go/src/runtime/signal_windows.go:249 +0x213 fp=0xe00ebff5b8 sp=0xe00ebff570 pc=0xd0cc73
runtime.gentraceback(0xe000000000?, 0x0?, 0xc00000cc00?, 0xe00ebff968?, 0x0, 0x0, 0x64, 0x0, 0x7ffff1404fd0?, 0x0)
        C:/Program Files/Go/src/runtime/traceback.go:246 +0x8b6 fp=0xe00ebff930 sp=0xe00ebff5b8 pc=0xd1c176
runtime.traceback1(0xc0000376c0?, 0xe0a500?, 0x3?, 0xc0000376c0, 0x0?)
        C:/Program Files/Go/src/runtime/traceback.go:846 +0x1b1 fp=0xe00ebffaf0 sp=0xe00ebff930 pc=0xd1e591
runtime.traceback(...)
        C:/Program Files/Go/src/runtime/traceback.go:793
runtime.tracebackothers.func1(0xc0000376c0)
        C:/Program Files/Go/src/runtime/traceback.go:1062 +0xe5 fp=0xe00ebffb30 sp=0xe00ebffaf0 pc=0xd1f4e5
runtime.forEachGRace(0xe00ebffb98)
        C:/Program Files/Go/src/runtime/proc.go:592 +0x4d fp=0xe00ebffb60 sp=0xe00ebffb30 pc=0xcfcead
runtime.tracebackothers(0xc000084680?)
        C:/Program Files/Go/src/runtime/traceback.go:1048 +0xe5 fp=0xe00ebffbc8 sp=0xe00ebffb60 pc=0xd1f3c5
runtime.dopanic_m(0xc000084680, 0xcf98d5?, 0xe0a8ca?)
        C:/Program Files/Go/src/runtime/panic.go:1270 +0x225 fp=0xe00ebffc30 sp=0xe00ebffbc8 pc=0xcfa1c5
runtime.fatalthrow.func1()
        C:/Program Files/Go/src/runtime/panic.go:1125 +0x48 fp=0xe00ebffc70 sp=0xe00ebffc30 pc=0xcf9c28
runtime.systemstack()
        C:/Program Files/Go/src/runtime/asm_amd64.s:492 +0x4e fp=0xe00ebffc78 sp=0xe00ebffc70 pc=0xd260ee
[signal 0xc000001d code=0x0 addr=0x0 pc=0xdd53e1]

goroutine 68 [running]:
runtime.throw({0xe0a8ca?, 0xc0000c2240?})
        C:/Program Files/Go/src/runtime/panic.go:1047 +0x65 fp=0xc000059f98 sp=0xc000059f68 pc=0xcf9865
runtime.sigpanic()
        C:/Program Files/Go/src/runtime/signal_windows.go:273 +0x1af fp=0xc000059fe0 sp=0xc000059f98 pc=0xd0cc0f
runtime: g 68: unexpected return pc for github.com/huandu/go-tls.hackedGoexit called from 0xc0000211d0
stack: frame={sp:0xc000059fe0, fp:0xc000059fe8} stack=[0xc000058000,0xc00005a000)
0x000000c000059ee0:  0x0000000000d23bf9 <sync.runtime_Semrelease+0x0000000000000019>  0x0000000000000003
0x000000c000059ef0:  0x0000000000000000  0x0000000000000000
0x000000c000059f00:  0x000000c000059f38  0x0000000000d31d07 <sync.(*WaitGroup).Add+0x0000000000000087>
0x000000c000059f10:  0x0000000000de5120  0x0000000000d260d5 <runtime.systemstack+0x0000000000000035>
0x000000c000059f20:  0x0000000000cf9bac <runtime.fatalthrow+0x000000000000006c>  0x000000c000059f38
0x000000c000059f30:  0x000000c000037d40  0x0000000000cf9be0 <runtime.fatalthrow.func1+0x0000000000000000>
0x000000c000059f40:  0x000000c000037d40  0x0000000000cf9865 <runtime.throw+0x0000000000000065>
0x000000c000059f50:  0x000000c000059f68  0x000000c000059f88
0x000000c000059f60:  0x0000000000cf9865 <runtime.throw+0x0000000000000065>  0x000000c000059f70
0x000000c000059f70:  0x0000000000cf9880 <runtime.throw.func1+0x0000000000000000>  0x0000000000e0a8ca
0x000000c000059f80:  0x0000000000000005  0x000000c000059fd0 
0x000000c000059f90:  0x0000000000d0cc0f <runtime.sigpanic+0x00000000000001af>  0x0000000000e0a8ca
0x000000c000059fa0:  0x000000c0000c2240  0x000000c000086098
0x000000c000059fb0:  0x000000c000037d40  0x0000000000d802a0 <testing.(*B).RunParallel.func1.1+0x0000000000000000>
0x000000c000059fc0:  0x000000c0000860a0  0x000000c000059fb8
0x000000c000059fd0:  0x0000000000000000  0x0000000000dd53e1 <github.com/huandu/go-tls.hackedGoexit+0x0000000000000001>
0x000000c000059fe0: <0x000000c0000211d0 >0x000000c000021200
0x000000c000059ff0:  0x000000c000021230  0x000000c000021260
github.com/huandu/go-tls.hackedGoexit()
        ?:0 +0x1 fp=0xc000059fe8 sp=0xc000059fe0 pc=0xdd53e1
created by testing.(*B).RunParallel
        C:/Program Files/Go/src/testing/benchmark.go:781 +0x105
exit status 2
FAIL    command-line-arguments  6.589s
FAIL

I found a similar issue: sirupsen/logrus#904, the final solution was using gis instead of tls.Btw, The correct spelling of "并行" is parallel.

@bigwhite
Copy link
Owner

I have no windows environment to reproduce the problem. Have you tried the logrus's solution?

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

2 participants