Description
Mark Paluch opened DATAREDIS-531 and commented
The concurrent use of SCAN
and iteration over the resulting Cursor
causes various Exceptions using the Jedis Driver.
Test case: https://gist.github.com/mp911de/327cb876117bc1d74049aff25e5509cb
redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: 5
at redis.clients.jedis.Protocol.process(Protocol.java:154)
at redis.clients.jedis.Protocol.processMultiBulkReply(Protocol.java:196)
at redis.clients.jedis.Protocol.process(Protocol.java:147)
at redis.clients.jedis.Protocol.processMultiBulkReply(Protocol.java:196)
at redis.clients.jedis.Protocol.process(Protocol.java:147)
at redis.clients.jedis.Protocol.read(Protocol.java:205)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:242)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:248)
at redis.clients.jedis.BinaryJedis.hscan(BinaryJedis.java:3300)
at org.springframework.data.redis.connection.jedis.JedisConnection$5.doScan(JedisConnection.java:3437)
java.lang.ClassCastException: [B cannot be cast to java.util.List
at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:242)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:248)
at redis.clients.jedis.BinaryJedis.hscan(BinaryJedis.java:3300)
at org.springframework.data.redis.connection.jedis.JedisConnection$5.doScan(JedisConnection.java:3437)
This issue gets only visible if:
- Multiple threads try to use the
SCAN
command and iterate over the resultingCursor
- There is enough data to keep the iteration busy
The reason is that the resulting Cursor
s hold a reference to the connection that was allocated during the .scan()
invocation. .scan()
allocates a connection but then it releases the connection back and so can multiple Cursors
in different Thread
s share the same Jedis connection
Affects: 1.7.2 (Hopper SR2)
Reference URL: redis/jedis#918
Attachments:
- SpringDataRedisTests.java (3.02 kB)
Issue Links:
-
DATAREDIS-550 ScanCursor holds reference to closed/released lettuce connection
-
DATAREDIS-454 SSCAN: Connection Used After Being Released
("supersedes") -
DATAREDIS-382 Using SCAN commands causes issues with Jedis in multi-threaded use
("supersedes")
Referenced from: pull request #218