spring-projects / spring-projects/spring-data-redis

"Invalidated object not currently part of this pool" occurs when transaction readOnly [DATAREDIS-677]

Open
#1,252 0 comments 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Dec 30, 2020.

in: core type: bug
Dominant language
Java
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

tyotann opened DATAREDIS-677 and commented

when i update spring-data-redis to version 1.8.4.RELEASE,i run script


		TransactionSynchronizationManager.setCurrentTransactionReadOnly(true);

		return redisTemplate.executePipelined(new SessionCallback<Object>() {

			@SuppressWarnings("unchecked")
			@Override
			public <K, V> Object execute(RedisOperations<K, V> operations) throws DataAccessException {

				HashOperations<T, Object, Object> hashOperations = (HashOperations<T, Object, Object>) operations.opsForHash();

				for (T key : keys) {

					if (CollectionUtils.isEmpty(hkeys)) {
						hashOperations.entries(key);
					} else {
						hashOperations.multiGet(key, hkeys);
					}
				}

				return null;
			}
		});

i will get error:

java.lang.IllegalStateException: Invalidated object not currently part of this pool
	at org.apache.commons.pool2.impl.GenericObjectPool.invalidateObject(GenericObjectPool.java:640)
	at redis.clients.util.Pool.returnBrokenResourceObject(Pool.java:101)
	at redis.clients.jedis.JedisPool.returnBrokenResource(JedisPool.java:239)
	at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:255)
	at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:16)
	at org.springframework.data.redis.connection.jedis.JedisConnection.close(JedisConnection.java:303)
	at org.springframework.data.redis.core.RedisConnectionUtils.releaseConnection(RedisConnectionUtils.java:212)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:217)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:157)
	at org.springframework.data.redis.core.RedisTemplate.executePipelined(RedisTemplate.java:247)
	at org.springframework.data.redis.core.RedisTemplate.executePipelined(RedisTemplate.java:236)

i found 1.7.3 change log:https://docs.spring.io/spring-data/redis/docs/current/changelog.txt

  • DATAREDIS-548 - Connection should be released when used with read-only transactions.

i debug the code,found call following code twice

RedisConnectionUtils.releaseConnection
		if (isConnectionTransactional(conn, factory)
				&& TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
			unbindConnection(factory);
		} else if (!isConnectionTransactional(conn, factory)) {
			if (log.isDebugEnabled()) {
				log.debug("Closing Redis Connection");
			}
			conn.close();
		}

the first time when TransactionSynchronizationManager.isCurrentTransactionReadOnly()==true, then unbindConnection;
the second time !isConnectionTransactional(conn, factory) == true, An exception occurs when conn.close()is executed;


Affects: 1.8.3 (Ingalls SR3)

1 votes, 1 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.