Skip to content

JedisPool exhausted in Jedis 2.10.0 #1920

@raytz

Description

@raytz

Jedis.java

@Override
public void close() {
    if (dataSource != null) {
        if (client.isBroken()) {
            this.dataSource.returnBrokenResource(this);
        } else {
            this.dataSource.
                    returnResource(this);
        }
        this.dataSource = null;  // <-- This line 
    } else {
        super.close();
    }
}

JedisSentinelPool.java

@Override
public Jedis getResource() {
    while (true) {
        Jedis jedis = super.getResource();
        jedis.setDataSource(this);  // <-- This line 

        // get a reference because it can change concurrently
        final HostAndPort master = currentHostMaster;
        final HostAndPort connection = new HostAndPort(jedis.getClient().getHost(), jedis.getClient()
                .getPort());

        if (master.equals(connection)) {
            // connected to the correct master
            return jedis;
        } else {
            returnBrokenResource(jedis);
        }
    }
}

In the case of concurrency

  1. Thread A return an object but not run to "this.dataSource = null" yet

  2. Thread B borrow an object and set dataSource to this;

  3. And Then Thread A run this.dataSource = null;

  4. Finally Thread A will never returnResource because dataSource is null

Jedis version:

2.10.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions