Issue Description
jedisCluster.ssubscribe(pubSub, channel) this line blocks forever.
jedisCluster.ssubscribe(
pubSub,
"channel".getBytes()
);
because, it runs in a loop keeps pulling message afterwards. see JedisShardedPubSubBase::process(). Here is a simplified snippet
do {
Object reply = client.getUnflushedObject();
// process the message
} while (isSubscribed());
As a result, this line jedisCluster.ssubscribe(..) is usually invoked in a separate thread, for example a ThreadPool, to avoid blocking the main thread.
During termination(shutdown), people will usually to shutdown the threadPool, which internally will interrupt the threads.
But the process loop does not check for interrupted flag. Hence it is unaware that the thread that is running the process() call has been signalled to stop.
Therefore, the process loop keeps running while it should have exited upon interruption.
Expected behavior
JedisShardedPubSubBase::process should exit the "do while" loop upon thread interrupt.
Actual behavior
JedisShardedPubSubBase::process keeps running despite thread interrupt
Steps to reproduce:
- start a
JedisCluster
- call
JedisCluster::ssubscribe(...) on a different thread. can be in a thread pool or otherwise.
- interrupt the thread that's running
JedisCluster::ssubscribe(...)
- You should expect to see consumption continues still, which means the thread will still be stuck at this line:
JedisCluster::ssubscribe(...)
Redis / Jedis Configuration
This is not related to configuration.
Jedis version:
5.0.0
Redis version:
latest
Java version:
openjdk 17
Suggested Fix:
do {
Object reply = client.getUnflushedObject();
// process the message
} while (!Thread.currentThread.isInterrupted() && isSubscribed());
Issue Description
jedisCluster.ssubscribe(pubSub, channel) this line blocks forever.
because, it runs in a loop keeps pulling message afterwards. see
JedisShardedPubSubBase::process(). Here is a simplified snippetAs a result, this line
jedisCluster.ssubscribe(..)is usually invoked in a separate thread, for example a ThreadPool, to avoid blocking the main thread.During termination(shutdown), people will usually to shutdown the threadPool, which internally will interrupt the threads.
But the process loop does not check for interrupted flag. Hence it is unaware that the thread that is running the process() call has been signalled to stop.
Therefore, the process loop keeps running while it should have exited upon interruption.
Expected behavior
JedisShardedPubSubBase::processshould exit the "do while" loop upon thread interrupt.Actual behavior
JedisShardedPubSubBase::processkeeps running despite thread interruptSteps to reproduce:
JedisClusterJedisCluster::ssubscribe(...)on a different thread. can be in a thread pool or otherwise.JedisCluster::ssubscribe(...)JedisCluster::ssubscribe(...)Redis / Jedis Configuration
This is not related to configuration.
Jedis version:
5.0.0
Redis version:
latest
Java version:
openjdk 17
Suggested Fix: