WebSocketV1ClientBase.lastReceivedTime field data race
filinvadim opened this issue · 6 comments
filinvadim commented
WARNING: DATA RACE
Write at 0x00c000158128 by goroutine 56:
.../pkg/client/websocketclientbase.(*WebSocketV1ClientBase).readLoop()
.../pkg/client/websocketclientbase/websocketv1clientbase.go:212 +0x23c
Previous write at 0x00c000158128 by goroutine 16:
.../pkg/client/websocketclientbase.(*WebSocketV1ClientBase).startTicker()
.../pkg/client/websocketclientbase/websocketv1clientbase.go:137 +0xbc
filinvadim commented
Just:
p.timeMutex.Lock()
p.lastReceivedTime = time.Now()
p.timeMutex.Unlock()
filinvadim commented
Same for WebSocketV2ClientBase
eynzhang commented
@filinvadim thanks for the feedback, usually this won’t happen, however it has possibility in theory as lastReceivedTime is written in two routines. I don’t want to introduce mutex, so just move the lastReceivedTime initialization to earlier places. You can check the latest master branch.
filinvadim commented
@eynzhang so data race is still in place. You need a mutex, sorry.
eynzhang commented
@filinvadim could you share how you reproduce this issue?
filinvadim commented
Sorry no, @eynzhang . It's in your code. Just go run --race ...
You have access to the variable lastReceivedTime
from 2 threads - tickerLoop and readLoop. That's data race. Reopen please to warn other developers.