Skip to content

JedisPool exhausted in Jedis 2.10.0 #1920

Closed
@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

Activity

gkorland

gkorland commented on Dec 23, 2018

@gkorland
Contributor

See #1911

sazzad16

sazzad16 commented on Dec 24, 2018

@sazzad16
Contributor

@gkorland Isn't this issue actually related to #1918 ?

added a commit that references this issue on Dec 25, 2018
02f2cc5
oliverbestmann

oliverbestmann commented on Dec 28, 2018

@oliverbestmann

Sorry, looks like this is still broken in 2.10.1. We are still leaking connections.

kutzi

kutzi commented on Jan 7, 2019

@kutzi
Contributor

Is there any update on this? Should we open a new bug against 2.10.1?

sazzad16

sazzad16 commented on Jan 7, 2019

@sazzad16
Contributor
pavel-hp

pavel-hp commented on Jan 15, 2019

@pavel-hp

@gkorland
We moved from version 2.9.0 to 2.10.1 and we've faced with the same issue.
Leaking connection to Redis.

All our threads have this StackTrace (it waits infinite time)

java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006404ef2d0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:587)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:440)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361)
at redis.clients.util.Pool.getResource(Pool.java:50)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:235)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:70)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:110)
at redis.clients.jedis.JedisClusterCommand.runBinary(JedisClusterCommand.java:77)
at redis.clients.jedis.BinaryJedisCluster.evalsha(BinaryJedisCluster.java:1403)

added a commit that references this issue on Jan 17, 2019
291d37b
added a commit that references this issue on Jan 17, 2019
bcc0265
self-assigned this
on Jan 20, 2019
added this to the 2.10.2 milestone on Jan 20, 2019

22 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @kutzi@gkorland@NitishBangera@loop@oliverbestmann

      Issue actions

        JedisPool exhausted in Jedis 2.10.0 · Issue #1920 · redis/jedis