Potential wrong lock handling at session.go
dkropachev opened this issue · comments
Dmitry Kropachev commented
Please answer these questions before submitting your issue. Thanks!
What version of Gocql are you using?
master
Lines 232 to 234 in 9dd9a7f
s.control.getConn()
can return different connection on each call, at least one path is possible when c.attemptReconnectToAnyOfHosts
is executed in parallel.
Which means that this code can lock one connection and unlock another:
s.control.getConn().conn.mu.Lock() # connection1 is locked
# c.attemptReconnectToAnyOfHosts executed in parallel replacing `s.control.getConn().conn` with new value
s.tabletsRoutingV1 = s.control.getConn().conn.tabletsRoutingV1
s.control.getConn().conn.mu.Unlock() # connection2 is unlocked
Suggested code:
conn := s.control.getConn().conn
conn.Lock()
s.tabletsRoutingV1 = conn.tabletsRoutingV1
conn.Unlock()
Also probably it makes sense to make getter
for tabletsRoutingV1
that would Lock/Unlock