amakawa / redic

Lightweight Redis Client
MIT License
120 stars 14 forks source link

Prevent concurrent 'RuntimeError: not connect' exception #15

Closed igor04 closed 5 years ago

igor04 commented 5 years ago

currently there is space between checking/establishing connection (1) and performing some action (2), and this space is increased due to synchronization

establish_connection unless connected? # (1)

@semaphore.synchronize do
  yield # (2)
end

as result we could have concurrent issue in place where all threads pass checking/establishing connection (1) and are waiting to perform action (2), if in one of such threads connection will be lost, it will retry to establish new connection but during this time rest of threads will fail with exception like:

gems/redic-1.5.0/lib/redic/client.rb:30:in `write' 

RuntimeError: not connected
soveran commented 5 years ago

Thank you!

soveran commented 5 years ago

Your change was released with version 1.5.2 :-)

igor04 commented 4 years ago

PS: described how the issue was spotted https://medium.com/@igor04/prevent-concurrent-exception-in-ohm-redic-494cb8d66e10