Skip to content

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

Open
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions