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

Potential wrong lock handling at session.go #157

Open
dkropachev opened this issue Jan 30, 2024 · 0 comments
Open

Potential wrong lock handling at session.go #157

dkropachev opened this issue Jan 30, 2024 · 0 comments

Comments

@dkropachev
Copy link

dkropachev commented Jan 30, 2024

Please answer these questions before submitting your issue. Thanks!

What version of Gocql are you using?

master

gocql/session.go

Lines 232 to 234 in 9dd9a7f

s.control.getConn().conn.mu.Lock()
s.tabletsRoutingV1 = s.control.getConn().conn.tabletsRoutingV1
s.control.getConn().conn.mu.Unlock()

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

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

1 participant