You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Message structure that I am sending and receiving from a channel. the first go routine asks for Messages from a sync.pool, ensures the Values and Fields properties are empty and sends the message to a channel. When all the messages have been sent the channel is closed
The receiver uses range to take a message of the channel, alters the Fields and Values and then gives the message back to the pool.
Eventually a message from the pool is re-used and has Fields and Values set. These are then reset back to zero length map and array but sometimes this fails and the length of fields is > 0 causing the panic.
Note : this does not seem to exhibit the issue on the playground, however ti is fairly consistent on an SMP machine, certainly on my 16 core HT machine.
What did you expect to see?
I do not expect a panic to occur, the Fields and Values should be zero length
What did you see instead?
panic: Fields greater than zero
goroutine 4 [running]:
panic(0x459e40, 0xc42000a190)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
main.main.func1(0xc420092060)
/home/I049472/godev/src/matt/epic/examples/test/test2.go:37 +0x1b4
created by main.main
/home/I049472/godev/src/matt/epic/examples/test/test2.go:42 +0x8a
exit status 2
Interestingly if I remove the modification of the Values array, which is obviously not even checked in the panic, then the issue does not arise. https://play.golang.org/p/xwrJicCgYA
The text was updated successfully, but these errors were encountered:
In for m := range ch, you have a single memory location m, that is the same for all iterations. When you messagePool.Put(&m), you store the address of that location in the pool. That means you can concurrently set m.Fields to an empty map and a non-empty map, writing to the same memory location. This is a race condition in your code.
What version of Go are you using (
go version
)?go version go1.7.3 linux/amd64
What operating system and processor architecture are you using (
go env
)?linux/amd64
32 cpu - Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
What did you do?
https://play.golang.org/p/jcpEGvgWFm
I have a Message structure that I am sending and receiving from a channel. the first go routine asks for Messages from a sync.pool, ensures the Values and Fields properties are empty and sends the message to a channel. When all the messages have been sent the channel is closed
The receiver uses range to take a message of the channel, alters the Fields and Values and then gives the message back to the pool.
Eventually a message from the pool is re-used and has Fields and Values set. These are then reset back to zero length map and array but sometimes this fails and the length of fields is > 0 causing the panic.
Note : this does not seem to exhibit the issue on the playground, however ti is fairly consistent on an SMP machine, certainly on my 16 core HT machine.
What did you expect to see?
I do not expect a panic to occur, the Fields and Values should be zero length
What did you see instead?
panic: Fields greater than zero
goroutine 4 [running]:
panic(0x459e40, 0xc42000a190)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
main.main.func1(0xc420092060)
/home/I049472/godev/src/matt/epic/examples/test/test2.go:37 +0x1b4
created by main.main
/home/I049472/godev/src/matt/epic/examples/test/test2.go:42 +0x8a
exit status 2
Interestingly if I remove the modification of the Values array, which is obviously not even checked in the panic, then the issue does not arise.
https://play.golang.org/p/xwrJicCgYA
The text was updated successfully, but these errors were encountered: