Fixed - Redisson.shutdown blocks calling thread. #2306

pull/2329/head
Nikita Koksharov 6 years ago
parent 2f7b089a14
commit 941ce121dc

@ -151,6 +151,10 @@ public final class RedisClient {
return config;
}
public Timer getTimer() {
return timer;
}
public RedisConnection connect() {
try {
return connectAsync().syncUninterruptibly().getNow();
@ -311,7 +315,12 @@ public final class RedisClient {
}
public RFuture<Void> shutdownAsync() {
final RPromise<Void> result = new RedissonPromise<Void>();
RPromise<Void> result = new RedissonPromise<Void>();
if (channels.isEmpty()) {
shutdown(result);
return result;
}
ChannelGroupFuture channelsFuture = channels.newCloseFuture();
channelsFuture.addListener(new FutureListener<Void>() {
@Override
@ -321,11 +330,24 @@ public final class RedisClient {
return;
}
if (!hasOwnTimer && !hasOwnExecutor && !hasOwnResolver && !hasOwnGroup) {
result.trySuccess(null);
return;
shutdown(result);
}
});
for (Channel channel : channels) {
RedisConnection connection = RedisConnection.getFrom(channel);
if (connection != null) {
connection.closeAsync();
}
}
return result;
}
private void shutdown(RPromise<Void> result) {
if (!hasOwnTimer && !hasOwnExecutor && !hasOwnResolver && !hasOwnGroup) {
result.trySuccess(null);
} else {
Thread t = new Thread() {
@Override
public void run() {
@ -355,16 +377,6 @@ public final class RedisClient {
};
t.start();
}
});
for (Channel channel : channels) {
RedisConnection connection = RedisConnection.getFrom(channel);
if (connection != null) {
connection.closeAsync();
}
}
return result;
}
@Override

Loading…
Cancel
Save