question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Thread-safety problem in RoundRobinJedisPool

See original GitHub issue

First of all, issue raised up from io.codis.jodis:0.4.1. We have frequently ran into exception Pool not open which threw by RedisPool

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 holds JedisPool: 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:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Apache9commented, Jul 20, 2018

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.

0reactions
Apache9commented, Sep 4, 2018

Please try 0.5.1.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found