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
If we look at connection.rb and how it handles the sockets, socket, and reset methods, there is an issue that only appears is true concurrency environments like JRuby: multiple threads can try to mutate the cache hashes at once.
Since code calls the socket method multiple times, it means that two calls can return two different sockets if threads clobbered the hash creation/access/etc...
To fix this, a Mutex needs to be defined per-connection and these three methods need to be wrapped in mutex.synchornize blocks.
This is an extreme edge case that requires:
A shared connection object between threads
Extreme lack of luck with timing
A ruby interpreter with actual parallelism (this will never happen on CRuby)
Also, you might want to use ObjectSpace::WeakMap for the per-thread cache to avoid memory leaks.
The text was updated successfully, but these errors were encountered:
If we look at
connection.rb
and how it handles thesockets
,socket
, andreset
methods, there is an issue that only appears is true concurrency environments like JRuby: multiple threads can try to mutate the cache hashes at once.Since code calls the
socket
method multiple times, it means that two calls can return two different sockets if threads clobbered the hash creation/access/etc...To fix this, a
Mutex
needs to be defined per-connection and these three methods need to be wrapped inmutex.synchornize
blocks.This is an extreme edge case that requires:
Also, you might want to use ObjectSpace::WeakMap for the per-thread cache to avoid memory leaks.
The text was updated successfully, but these errors were encountered: