DATAREDIS-840 - Catch unsubscribe exceptions when stopping RedisMessageListenerContainer.
We now catch exceptions that may occur during unsubscription from the subscribed patterns/channels. Previously, RuntimeExceptions were not caught and prevented a fast shutdown of the ApplicationContext. Original Pull Request: #346
This commit is contained in:
committed by
Christoph Strobl
parent
afd8606e19
commit
bb1dd8b379
@@ -847,27 +847,40 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Cancelling Redis subscription...");
|
||||
}
|
||||
if (connection != null) {
|
||||
Subscription sub = connection.getSubscription();
|
||||
if (sub != null) {
|
||||
synchronized (localMonitor) {
|
||||
|
||||
if (connection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Subscription sub = connection.getSubscription();
|
||||
if (sub != null) {
|
||||
synchronized (localMonitor) {
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Unsubscribing from all channels");
|
||||
}
|
||||
|
||||
try {
|
||||
sub.pUnsubscribe();
|
||||
sub.unsubscribe();
|
||||
if (subscriptionTaskRunning) {
|
||||
try {
|
||||
localMonitor.wait(subscriptionWait);
|
||||
} catch (InterruptedException e) {
|
||||
// Stop waiting
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if (!subscriptionTaskRunning) {
|
||||
closeConnection();
|
||||
} else {
|
||||
logger.warn("Unable to close connection. Subscription task still running");
|
||||
} catch (Exception e) {
|
||||
logger.warn("Unable to unsubscribe from subscriptions", e);
|
||||
}
|
||||
|
||||
if (subscriptionTaskRunning) {
|
||||
try {
|
||||
localMonitor.wait(subscriptionWait);
|
||||
} catch (InterruptedException e) {
|
||||
// Stop waiting
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
if (!subscriptionTaskRunning) {
|
||||
closeConnection();
|
||||
} else {
|
||||
logger.warn("Unable to close connection. Subscription task still running");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user