Thread-safety problem in RoundRobinJedisPool
See original GitHub issueFirst of all, issue raised up from io.codis.jodis:0.4.1. We have frequently ran into exception
Pool not open
which threw byRedisPool
RoundRobinJedisPool.resetPools
is not thread-safety. Although RoundRobinJedisPool#pools
is carefully declared volatile
and ImmutableList
, the inner pool (thus, JedisPool
) can still be modified. At the end of resetPools
, it starts closing pool(s) that not exists under zookeeper path:
for (PooledObject pool: addr2Pool.values()) {
LOG.info("Remove proxy: " + pool.addr);
pool.pool.close();
}
this operation may close pool(s) already inited by other thread (and successfully assigned to RoundRobinJedisPool#pools
) by mistake. For example:
pools
holdsJedisPool
: a, b, c- Thread A reads a, b, c from zookeeper
- Thread B reads a, b from zookeeper
- Thread B build new list instance, then assign to
pools
(anyway it loses the competition) - Thread A build new list instance (note that reference of a, b, c were copied), then assign to
pools
- Thread B start closing resources c
This makes pools
contains a closed JedisPool
c.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Why isn't there a thread safe jedis client implemented? #812
I agree. I have been using JedisPool extensively for all multithreaded applications to re-use jedis objects. But when I see a thread safe...
Read more >Why A single Jedis instance is not threadsafe? - redis
A single Jedis instance is not threadsafe because it was implemented this way. That's the decision that the author of the library made....
Read more >Multithreading jedis
Jedis is not thread safe (should add that to the documentation). You can either use one Jedis per thread or JedisPool, which is...
Read more >Randomized Round Robin (Load Balancing) as Fast as ...
The load balancer must, therefore, be thread-safe. Requests may come in repeating patterns that should be broken up by the load balancer ...
Read more >Thread safety with affine thread pools
We simply enqueue a work item on a shared queue and wake up worker agents in round robin fashion. While this is not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is it possible that two threads want to call resetPools concurrently? IIRC, the curator will always uses a single threaded thread pool to execute the callbacks. If not, then we need to add a synchronized modifier to the resetPools method.
Please try 0.5.1.